您的位置:首页 > 运维架构 > Linux

linux文件交集差集

2016-08-28 21:14 288 查看
 


linux文件交集差集

目录(?)[+]

comm命令:

comm file1 file2

在没有指定可选参数,默认会输出三列: 只在file1中的数据,只在file2中的数据以及file1和file2的交集。也可以指定如下参数:

[plain] view
plain copy

 

 





-1              suppress column 1 (lines unique to FILE1)  

-2              suppress column 2 (lines unique to FILE2)  

-3              suppress column 3 (lines that appear in both files)  

e.g.

[plain] view
plain copy

 

 





cat a.txt   

a  

b  

c  

d  

e  

f  

[plain] view
plain copy

 

 





cat b.txt    

a  

b  

c  

e  

w  

[plain] view
plain copy

 

 





comm a.txt b.txt   

                a  

                b  

                c  

d  

                e  

f  

        w  


求两个文件的交集

[plain] view
plain copy

 

 





comm -12 a.txt b.txt   

a  

b  

c  

e  

求两个文件的差集

在file2不在file1中的数据

[plain] view
plain copy

comm -13 a.txt b.txt    

w  

在file1不在file2中的数据

[plain] view
plain copy

 

 





comm -23 a.txt b.txt    

d  

f  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: