Sunday, October 10, 2010

bash set theory

Intersection of two files:
$ cat one
a
b
c
$ cat two
b
c
d
e
$ for x in `cat one`; do grep $x two; done
b
c
$
Complement of two files:
$ cat one
a
b
c
$ cat two
b
c
d
e
$ sort one one two | uniq -u
d
e
$ sort two two one | uniq -u
a
$ 
After playing around for a little I found Peteris Krumins' blog who provided the complement method I'm pasting above.

No comments: