Comparing files with `comm`
  •  1 min read

Sorted files can be compared line by line with comm.

file1.txt             file2.txt
--------              --------
Apple                 Apple
Banana                Banana
Grape                 Cherry
Orange                Grape
Pear                  Orange
Plum                  Peach
Strawberry            Pear

(-12) Lines found in the both files

comm -12 file1.txt file2.txt
Apple
Banana
Grape
Orange
Pear

(-23) Lines found only in file1.txt

comm -23 file1.txt file2.txt
Plum
Strawberry

(-13) Lines found only in file2.txt

comm -13 file1.txt file2.txt
Cherry
Peach