comm Command
Purpose
Selects or rejects lines common to two sorted files.
Syntax
Description
Note: If you specify - (minus) for one of the file names, the comm command reads standard input.
The comm command reads the File1 and File2 parameters and writes, by default, a three-column output to standard output. The columns consist of:
- Lines that are only in File1
- Lines that are only in File2
- Lines that are in both File1 and File2.
Both File1 and File2 should be sorted according to the collating sequence specified by the current National Language environment.
Flags
Item | Description |
---|---|
-1 | Suppresses the display of the first column (lines in File1). |
-2 | Suppresses the display of the second column (lines in File2). |
-3 | Suppresses the display of the third column (lines common to File1 and File2). |
Exit Status
This command returns the following exit values:
Item | Description |
---|---|
0 | All input files were output successfully. |
>0 | An error occurred. |
Examples
- To display the lines unique
to each file and common to both, enter:
If the files things.to.do and things.done contain the following lists:comm things.to.do things.done
then the comm command displays:things.to.do buy soap groceries luncheon meeting at 3 system update tech. review things.done 2nd revision interview luncheon system update tech. review weekly report
The first column contains the lines found only in things.to.do. The second column, indented with a tab character, lists the lines found only in things.done. The third column, indented with two tabs, lists the lines common to both.2nd revision buy soap groceries interview luncheon meeting at 3 system update tech. review weekly report
- To display the lines that
appear in only one file, enter:
This suppresses the second and third columns of the comm command listing. If the files are the same as in Example 1, then the following is displayed:comm -23 things.to.do things.done
buy soap groceries meeting at 3
File
Item | Description |
---|---|
/usr/bin/comm | Contains the comm command. |