Unix command to find lines common in two files

too much php picture too much php · Dec 17, 2008 · Viewed 154.8k times · Source

I'm sure I once found a unix command which could print the common lines from two or more files, does anyone know its name? It was much simpler than diff.

Answer

Jonathan Leffler picture Jonathan Leffler · Dec 17, 2008

The command you are seeking is comm. eg:-

comm -12 1.sorted.txt 2.sorted.txt

Here:

-1 : suppress column 1 (lines unique to 1.sorted.txt)

-2 : suppress column 2 (lines unique to 2.sorted.txt)