sort和uniq求两个文件的并集,交集和差集

uniq - report or omit repeated lines

  • uniq 去除重复的行,最终结果包含重复和非重复的行。
  • uniq -u 只打印非重复的行。
  • uniq -d 只打印重复的行。

并集:cat file1.txt file2.txt | sort | uniq > file.txt

交集:cat file1.txt file2.txt | sort | uniq -d >file.txt

差集:求file1.txt相对于file2.txt的差集,可先求出两者的交集temp.txt,然后在file1.txt中除去temp.txt即可。

     cat file1.txt file2.txt | sort | uniq -d >temp.txt

     cat file1.txt temp.txt | sort | uniq -u >file.txt

posted @ 2020-01-02 16:56  IUNI_JM  阅读(725)  评论(0编辑  收藏  举报