码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-08-30 19:53:59      阅读:117      评论:0      收藏:0      [点我收藏+]

标签: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求两个文件的并集,交集和差集

标签:sort   uniq   

原文地址:http://chenxiaotao.blog.51cto.com/11430805/1961049

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!