Skip to main content

Compare two sorted files line-by-line.

# To produce three tab-separated columns: lines only in first file, lines only in second file and common lines.
comm <file1> <file2>

# To print only lines common to both files.
comm -12 <file1> <file2>

# To print only lines common to both files, read one file from stdin.
cat <file1> | comm -12 - <file2>

# To print lines only found in first file.
comm -23 <file1> <file2>

# To print lines only found in second file.
comm -13 <file1> <file2>