Linux的comm命令如何使用
更新:HHH   时间:2023-1-7


这篇“Linux的comm命令如何使用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Linux的comm命令如何使用”文章吧。

准备文件1.txt和2.txt

[h_chenliling@vm6-sj1-pro-had-32-107 ~]$ cat 1.txt
a
b
c
d
e
f1234567
[h_chenliling@vm6-sj1-pro-had-32-107 ~]$ cat 2.txt
d
e
f
g
h
i1234567
[h_chenliling@vm6-sj1-pro-had-32-107 ~]$ comm 1.txt 2.txt
a
b
c
       d
       e
       f
   g
   h
   i12345678910

第一列只包含在1.txt中出现的行,第二列包含在2.txt中出现的行,第三列包含在1.txt和2.txt中相同的行。各列是以制表符(\t)作为定界符。

交集

删除第1列和第2列

[h_chenliling@vm6-sj1-pro-had-32-107 ~]$ comm 1.txt 2.txt  -1 -2
d
e
f1234

差集

1.txt的差集,1.txt存在,而2.txt中不存在。也就是删除第2列和第3列

[h_chenliling@vm6-sj1-pro-had-32-107 ~]$ comm 1.txt 2.txt  -2 -3
a
b
c1234

求差

两个文件不相同的行,删除第3列,合并第1列和第2列

[h_chenliling@vm6-sj1-pro-had-32-107 ~]$ comm 1.txt 2.txt  -3 | sed 's/^\t//'a
b
c
g
h
i

以上就是关于“Linux的comm命令如何使用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注天达云行业资讯频道。

返回开发技术教程...