comm - compare two sorted files line by line 逐行比较两个排序好的文件,可以用sort来排序。友情链接:Linux sort命令
命令格式:comm [OPTION]...FILE1 FILE2 更多详细信息,可以参考man comm页面
如果没有参数,comm将输出三列,第一列是只属于FILE1文件的,第二列是只属于FILE2文件的,第三列是同时属于两个文件的。
-1:不输出第一列
-2:不输出第二列
-3:不输出第三列
上面的-1,-2,-3可以组成复合的选项,e.g.-12,表示只输出第三列;-13,表示只输出第二列
--nocheck-order 不检查被比较文件是否已经排序
例子:
[root@rhel6164 comm]# cat test1.txt #原始文件,已经排序好了
100
101
102
103
[root@rhel6164 comm]# cat test2.txt #原始文件,已经排序好了
102
103
104
105
[root@rhel6164 comm]# comm test1.txt test2.txt #不加任何选项,输出三列,第一列是test1.txt独有的,第二列是test2.txt独有的,第三列是test1.txt和test2.txt共有的
100
101
102
103
104
105
[root@rhel6164 comm]# comm -12 test1.txt test2.txt #只输出第3列,test1.txt和test2.txt共有的
102
103