comm flags & options
Basic usage
Compare two sorted files. Outputs three columns: lines unique to file1, lines unique to file2, lines in both.
comm file1.txt file2.txt
-1
Suppress column 1 (lines unique to file1).
comm -1 file1.txt file2.txt
-2
Suppress column 2 (lines unique to file2).
comm -2 file1.txt file2.txt
-3
Suppress column 3 (lines common to both files).
comm -3 file1.txt file2.txt
Lines only in file1
Suppress columns 2 and 3.
comm -23 file1.txt file2.txt
Lines only in file2
Suppress columns 1 and 3.
comm -13 file1.txt file2.txt
Lines common to both
Suppress columns 1 and 2.
comm -12 file1.txt file2.txt
With unsorted input
Sort files inline using process substitution.
comm -12 <(sort file1.txt) <(sort file2.txt)
--check-order
Verify that input is sorted and fail if not.
comm --check-order file1.txt file2.txt