LoginSignup
22
19

More than 5 years have passed since last update.

コマンドラインで集合演算

Last updated at Posted at 2014-03-26

コマンド出力の差分に対してとある処理をしたかったので汎用部分をまとめてみた
入力A
$ cat A
a
b
c
a
b
c

入力B
$ cat B
A
b
C
A
b
C

積集合
$ join <(cat A|sort -u) <(cat B|sort -u)
b

差集合
$ cat <(cat A|sort -u) <(join <(cat A|sort -u) <(cat B|sort -u) ) | sort | uniq -u
a
c

22
19
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
19