Skip to main content

find only common lines in two files

How to find all lines in two files which both files do have in common:

cat FILE1 FILE2 | sort | uniq -d

If they are sorted already this works to:

comm -12 FILE1 FILE2

else:

comm -12 <(sort FILE1 | uniq) <(sort FILE2 | uniq)