Skip to content

Get union, intersection and difference of 2 files with uniq

巧用 sortuniq 得到两个文件的交集、并集、差集

$ cat A
aa
bbb
1.1.11.1
2.2.2.2

$ cat B
2.2.2.2
bbb
ccc
ddd
10.10.10

并集 union

sort A B |uniq

交集 intersection

sort A B |uniq -d

差集 difference

A - B

sort A B B |uniq -u

B - A

sort B A A |uniq -u