cat a b | sort | uniq > c # c is a union b 并集
cat a b | sort | uniq -d > c # c is a intersect b 交集
cat a b b | sort | uniq -u > c # c is set difference a - b 差集
查看a b文件内容
[root@localhost /]# cat a b
LUAN
SHOU
SHEN
LUAN
SHOU
SHEN
1111
2222
3333
LUAN
KEVIN
1234
1111
使用-c
cat a b |sort|uniq -c
2 1111
1 1234
1 2222
1 3333
1 KEVIN
3 LUAN
2 SHEN
2 SHOU
cat a b |sort|uniq //并集
1111
1234
2222
3333
KEVIN
LUAN
SHEN
SHOU
cat a b |sort|uniq -d //交集
1111
LUAN
SHEN
SHOU
cat a b |sort|uniq -u //差集
1234
2222
3333
KEVIN
转载于:https://blog.51cto.com/5471815/1294152