比较两个文件使用awk或sed的 [英] Compare two files with awk or sed
本文介绍了比较两个文件使用awk或sed的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这必须是您轻松
下面是文件1(一列)。
1
2
3
4
五
6
7
8
9
和这里是文件2(两列)。
2耶
3 UPS
4哇
8嘿嘿
必须有一个简单的单行打印出来行文件1的鸵鸟政策匹配到file2
解决方案
的awk'NR == FNR {a [$ 1] ++;旁;}!($ 0一)文件2文件1
或使用带有-v加盟,作为@迈克尔建议:
加入-v1文件1文件2
两者都将打印:
1
五
6
7
9
This must be easy for you
Here is file1 (one column)
1
2
3
4
5
6
7
8
9
and here is file2 (two columns)
2 yay
3 ups
4 wow
8 hey
There must be a simple one liner to print out lines in file1 that don´t match to file2
解决方案
awk 'NR==FNR{a[$1]++;next;}!($0 in a)' file2 file1
or using join with -v, as @Michael suggested:
join -v1 file1 file2
both will print :
1
5
6
7
9
这篇关于比较两个文件使用awk或sed的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文