1. 程式人生 > >利用sort和uniq求兩個文件的並集,交集和差集

利用sort和uniq求兩個文件的並集,交集和差集

sort uniq

 利用sort和uniq求兩個文件的並集,交集和差集

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

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

  差集:求file1.txt相對於file2.txt的差集,可先求出兩者的交集file3.txt,然後在file1.txt中除去file3.txt即可。

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

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


本文出自 “跛鱉千裏,貴在分享” 博客,請務必保留此出處http://chenxiaotao.blog.51cto.com/11430805/1961049

利用sort和uniq求兩個文件的並集,交集和差集