Tip #186 Using comm
You can use diff to see the differences between two files, but it can be useful to see what is the same and more clearly how they differ. This is where comm comes in useful.comm tells you what information is common to two lists and what information appears uniquely in one or the other.
$ find . -type f -print -exec cat {} \; ./1.txt a b c ./2.txt a c e $ comm 1.txt 2.txt a b c e
The first column shows lines only in the first file, the second column lines from the second file and the third column lines from both.
This can be made easier still by adding a bit of perl:
$ comm 1.txt 2.txt | perl -pe 's/^/1: /g;s/1: \t/2: /g;s/2: \t/A: /g;' | sort 1: b 2: e A: a A: c
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs