假如有这么两个文件test1和test2:


单纯的两个文件取交并差集,可以用awk或者comm等实现,但是有更简单的方法。
取交集:
sort test1 test2 | uniq -d
uniq -d是指输出重复行。
取并集:
sort test1 test2 | uniq
取差集:
sort test1 test2 | uniq -u
uniq -u是指的输出出现1次的行。
取并集可以考虑awk,也很简单:
awk '!a[$0]++' test1 test2
欢迎关注!
网友评论