diff 寻找差异
ref:Linux diff --比较两个文件并输出不同之处 - 老莫小小朋友 - CSDN博客
![](https://img.haomeiwen.com/i13325312/f79994e27f7ed9ba.png)
comm 寻找并集
两个文件必须是排序和唯一(sorted and unique)
默认输出为三列,第一列为是A-B,第二列B-A,第三列为A交B
comm -1 -2 <(sort a.txt|uniq ) <(sort b.txt|uniq )
comm -1 -2 <(sort a.txt|uniq ) <(sort b.txt|uniq ) | wc -l
comm -1 -2 <(sort a.txt|uniq ) <(sort b.txt|uniq ) | wc -l > overlap.txt
![](https://img.haomeiwen.com/i13325312/38aad5cdda809de0.png)
aaa.txt的差集 -2 -3 参数
bbb.txt的差集 -1 -3 参数
uniq取交集/并集:
ref:如何求两个文件的交集、并集和差集?------sort和uniq闪亮登场 - stpeace的专栏 - CSDN博客
交集:
sort a.txt | uniq > aa.txt
sort b.txt | uniq > bb.txt
cat aa.txt bb.txt | sort | uniq -d
并集:
cat 1.txt 2.txt | sort | uniq | wc -l
cat 1.txt 2.txt | sort | uniq > 3.txt
差集:
![](https://img.haomeiwen.com/i13325312/7bb9fed92997478f.png)
网友评论