首页 > 其他 > 详细

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

时间:2020-01-02 17:48:09      阅读:120      评论:0      收藏:0      [点我收藏+]

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

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

原文:https://www.cnblogs.com/jmliao/p/12133924.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!