Linux-comm命令

comm命令可以用于两个文件之间的比较,前提是两个文件必须有序。
准备文件1.txt和2.txt

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

第一列只包含在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
f

差集

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
c

求差

两个文件不相同的行,删除第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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值