Linux and Unix comm command

Quick links

About comm
Related commands
Linux and Unix main page

About comm

Compare two sorted files line-by-line.


comm [OPTION]... FILE1 FILE2


Compare sorted files FILE1 and FILE2 line-by-line.

With no options, comm produces three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. Each of these columns can be suppressed individually with options.



suppress column 1 (lines unique to FILE1)


suppress column 2 (lines unique to FILE2)


suppress column 3 (lines that appear in both files)


check that the input is correctly sorted, even if all input lines are pairable


do not check that the input is correctly sorted


separate columns with string STR


display a help message, and exit.


output version information, and exit.


comm -12 myfile1.txt myfile2.txt

Print only the lines present in both myfile1.txt and myfile2.txt.

comm -3 myfile1.txt myfile2.txt

Print only the lines that are present in myfile1.txt and not myfile2.txt, and vice versa.

Related commands

cmp — Compare two files byte by byte.
diff — Identify the differences between two files.
join — Join the lines of two files which share a common field of data.
sort — Sort the lines in a text file.
uniq — Identify, and optionally filter out, repeated lines in a file.