Linux have a lot of tools to compare files. These tools provides a lot of powerful features to meet user needs. But sometimes just simple comparison is enough for some users.
comm is a tool for this purpose . Comm only compare files and shows differences in a visual manner.
comm [OPTION]... FILE1 FILE2
$ comm --help
We will simply compare two files those have same and different lines. We just need to provide file names to the comm command. Here is our files.
Now we issue the command like below.
$ comm a.txt b.txt
As we can see the differences
lemon are printed in required column.
In previous example we see that there are some information about unsorted columns. comm command automatically checks the order of the provided text file. This can be disabled with
$ comm --nocheck-order a.txt b.txt
Columns can be suppressed with the suppress feature. We just need to provide column number to suppress like
- -1 suppress column 1 (lines unique to FILE1)
- -2 suppress column 2 (lines unique to FILE2)
- -3 suppress column 3 (lines that appear in both files)
$ comm -1 a.txt b.txt