commands

comm — compare sorted files

Compare sorted inputs in the same locale; columns contain lines unique to first, unique to second, and common to both. -12 suppresses columns 1 and 2, leaving common lines. Example assumes a fresh text-streams lab fixture.

Formal Syntax & Structure

linux syntaxlinux
comm [OPTION]... FILE1 FILE2

Parameters & Attributes

NameTypeDescription
-12optionSuppress first two columns
FILE1operandSorted first file
FILE2operandSorted second file

Return Value

exit status and output

For GNU comm, status 0 means the comparison completed, even when the inputs differ or the selected columns are empty. Nonzero indicates an error; compare the output to identify common or unique lines.

Working Example

Example Snippetlinux
LC_ALL=C comm -12 sorted-a.txt sorted-b.txt
Linux Reference