shell的集合运算

用cat,sort,uniq命令实现文件行的交集 、并集、补集

  • 交集 $F_1 \cap F_2 $
cat f1 f2 | sort | uniq -d
  • 并集 $F_1 \cup F_2 $
cat f1 f2 | sort | uniq 
  • 并集 - 交集 $F_1 \cup F_2 - F_1 \cap F_2 $
cat f1 f2 | sort | uniq -u

  • 补集 $ F_1 - F_2 = (F_1 \cup F_2 ) \cup F_2 - (F_1 \cup F_2 ) \cap F_2 $
cat f1 f2 | sort | uniq | cat f2 - | sort | uniq -u
posted @ 2015-08-25 12:40  bregman  阅读(4824)  评论(0编辑  收藏  举报