找到两个文件之间的区别 [英] Find the difference between two files
本文介绍了找到两个文件之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下情况:
file1.dat类似于:
The file1.dat is like:
1 2
1 3
1 4
2 1
和file2.dat就像:
and the file2.dat is like:
1 2
2 1
2 3
3 4
我想找到第二个文件与第一个文件之间的差异.我尝试了 grep -v -f file1 file2
,但是我的实际文件大于这两个文件,当我尝试使用它时,外壳永无止境地工作了.
I want to find the differences between the second file from the first. I tried wit grep -v -f file1 file2
but my real files are bigger than this two and when I tried with it the shell never ended is work.
结果应为:
2 3
3 4
文件已排序,并且它们具有相同数量的元素.用awk找到解决方案的任何方法吗?
The files are sorted and they have the same number of elements. Any way to find a solution with awk?
推荐答案
似乎您希望 file2
中的行不在 file1
中:
Seems like you want lines in file2
that are not in file1
:
$ awk 'FNR==NR{a[$0];next}!($0 in a)' file1 file2
2 3
3 4
但是使用 comm
更简单:
$ comm -13 file1 file2
2 3
3 4
这篇关于找到两个文件之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文