//Random Tip
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow

You are viewing a random entry, refresh your browser to change.

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


View Comments »




Comments 

Add your comment

Comments are currently disabled
No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit