【Shell】 计算文件 交集,并集和差集

文件 a.txt

a
c
1
3
d
4

b.txt

a
b
e
2
1
5

计算并集

sort -u a.txt b.txt
1
2
3
4
5
a
b
c
d
e

计算交集

grep -F -f a.txt b.txt | sort | uniq
1
a

计算差集

a-b

grep -F -v -f b.txt a.txt | sort | uniq
3
4
c
d

b-a

grep -F -v -f a.txt b.txt | sort | uniq
2
5
b
e
关注公众号 海量干货等你
原文地址:https://www.cnblogs.com/sowhat1412/p/12734204.html