comm is a useful Linux tool to use at the shell. It takes two files with sorted lines as input and displays which lines are unique to each file and which lines are common (intersection) to both. For example, this might be useful when comparing which files are common among two directories and so on. This tool is a part of coreutils package, so it should be available everywhere.
- To compare two files:
$ comm first.txt second.txt
You will see 3 columns in the output corresponding to lines unique to first file, lines unique to second file and lines common to both.
- To suppress columns 1 and 2, thus display only columns common to both files:
$ comm -1 -2 first.txt second.txt
- There are a few other options to this tool which can be read about in the manpage:
Tried with: Ubuntu 16.04