Skip to content

Get union, intersection and difference of 2 files with 1 line command

巧用 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

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback: dig +short txt issue.imzye.com
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Buy Me a Coffee