Back to the command reference

comm

FilesAdvanced In simulator In real Linux

Compare two sorted files column by column

Name: comm = common

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

comm compares two **sorted** files and prints three columns: lines only in file 1, lines only in file 2, and lines in both. Hiding columns with -1, -2 and -3 gives set differences or the intersection.

Syntax

comm [OPTION]... FILE1 FILE2

Common options

-1Suppress lines unique to FILE1
-2Suppress lines unique to FILE2
-3Suppress lines in both files
--check-orderCheck that the input is sorted (unsorted input gives wrong results)
--output-delimiter STRSeparate the columns with STR (a tab by default)

Examples

  • $ comm -12 a.txt b.txt

    Lines in both files (inputs must be sorted)

    Explain
  • $ comm -23 <(sort a.txt) <(sort b.txt)

    Lines only in a

    Explain

Related