[Shell command] Check whether two lists contain the same lines

Created on November 29, 2026

You can combine sort and comm to compare the lines in two files regardless of their original order. This example compares a.txt and b.txt.

a.txt

5
10
15
20
25

b.txt

10
5
15
25
20

Compare the sorted lists

comm -3 <(sort a.txt) <(sort b.txt)

comm requires sorted input. Bash process substitution (<(...)) passes each sorted list to comm. Its three output columns show lines exclusive to the first file, lines exclusive to the second file, and lines common to both. The -3 option suppresses the common lines.

This command produces no output because the two lists contain the same lines with the same counts. An extra occurrence of a repeated line would appear in the output.

Shell command