shell操作文件的几条命令:删除最后一列、删除第一行、diff等
2013-06-28 17:40
357 查看
删除文件第一行: sed '1d' filename
删除文件最后一列: awk '{print $NF}' filename
awk删除重复行的命令:awk '{if (!seen[$0]++) {print $0;}}' filename
比较文件的两种方法:
1)comm -3 --nocheck-order file1 file2
2) grep -v -f file1 file2 :输出file2中有file1中没有的行
当然还有diff file1 file2
贴一段昨天写的shell脚本~
删除文件最后一列: awk '{print $NF}' filename
awk删除重复行的命令:awk '{if (!seen[$0]++) {print $0;}}' filename
比较文件的两种方法:
1)comm -3 --nocheck-order file1 file2
2) grep -v -f file1 file2 :输出file2中有file1中没有的行
当然还有diff file1 file2
贴一段昨天写的shell脚本~
#!/bin/bash date_time=`date +'%H_%M_%S'` yesterday=`date -d"-1 day" +'%Y_%m_%d'` today=`date +'%Y_%m_%d'` date_day_time=`date +'%Y_%m_%d_%H_%M_%S'` mkdir /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/same_similiar_log/$today # begin to get input files which haven't been deal with today_input=/home/crawler/petabyte/crawllog/news_data/$today yesterday_input=/home/crawler/petabyte/crawllog/news_data/$yesterday /opt/hadoop/program/bin/hadoop fs -ls $yesterday_input/ > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get /opt/hadoop/program/bin/hadoop fs -ls $today_input/ >> /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get sed '1d' /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get_without_first_line awk '{print $NF}' /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_get_without_first_line > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input #comm -3 --nocheck-order /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_diff grep -v -f /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_diff awk '{print $NF}' /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_diff > /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/today_new_input mv /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/all_input /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done # begin to compute same_similary_news inputfile1="" while read line do inputfile1=$inputfile1,${line} done < /home/spamdetect/changxiaojia/workspace/finance/same_similar_news_mining/mid_files/input_done echo $inputfile1
相关文章推荐
- shell删除最后一列、删除第一行、比较文件
- shell删除最后一列、删除第一行、比较文件
- linux 下删除文件中的前三列 (也就是取第四列到最后一列的内容)
- 一天一个shell命令 linux文件操作系列-ln命令详解
- 一天一个shell命令 linux文件操作系列-ln命令详解
- Monkeyrunner 写脚本的技巧(shell 命令,文件操作)
- awk删除文件最后一列
- 【一天一个shell命令】文本操作系列-diff
- 使用java实现dos窗口文件操作命令(复制,删除,列出文件目录)
- Shell命令之-文件复制/删除/ 移动
- 一天一个shell命令 linux文本操作系列-diff命令详解
- 【Unix/Linux】【命令】【文件,目录操作工具】删除文件或目录——rm命令
- Shell 命令教程(一) 文件操作
- 老男孩教育每日一题-第61天-使用命令调换 /etc/passwd 文件里所有的第一列和最后一列位置
- 【一天一个shell命令】文件操作系列-ln
- Shell的文件操作函数SHFileOperation 移动,复制,删除文件
- adb shell命令 查看文件,删除文件
- Linux文件操作命令(创建、复制、剪切、删除)
- Linux系统的rm命令太危险,一不小心就会删除系统文件。写一个shell脚本来替换系统的rm命令,
- Linux中通过命令直接删除文件中最后一行