comm - select or reject lines common to two files
comm [-123] file1 file2
The comm utility will read file1 and file2, which should be ordered in the current collating sequence, and produce three text columns as output: lines only in file1; lines only in file2; and lines in both files.
If the lines in both files are not ordered according to the collating sequence of the current locale, the results are unspecified.
The comm utility supports the XBD specification, Utility Syntax Guidelines .
The following options are supported:
- Suppress the output column of lines unique to file1.
- Suppress the output column of lines unique to file2.
- Suppress the output column of lines duplicated in file1 and file2.
The following operands are supported:
- A pathname of the first file to be compared. If file1 is "-", the standard input is used.
- A pathname of the second file to be compared. If file2 is "-", the standard input is used.
If both file1 and file2 refer to standard input or to the same FIFO special, block special or character special file, the results are undefined.
The standard input will be used only if one of the file1 or file2 operands refers to standard input. See the INPUT FILES section.
The input files must be text files.
The following environment variables affect the execution of comm:
- Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
- If set to a non-empty string value, override the values of all the other internationalisation variables.
- Determine the locale for the collating sequence comm expects to have been used when the input files were sorted.
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
- Determine the location of message catalogues for the processing of LC_MESSAGES .
The comm utility will produce output depending on the options selected. If the -1, -2 and -3 options are all selected, comm will write nothing to standard output.
If the -1 option is not selected, lines contained only in file1 will be written using the format:
"%s\n", <line in file1>
If the -2 option is not selected, lines contained only in file2 will be written using the format:
"%s%s\n", <lead>, <line in file2>where the string <lead> is:
- if the -1 option is not selected, or
- null string
- if the -1 option is selected.
If the -3 option is not selected, lines contained in both files will be written using the format:
"%s%s\n", <lead>, <line in both>where the string <lead> is:
- if neither the -1 nor the -2 option is selected, or
- if exactly one of the -1 and -2 options is selected, or
- null string
- if both the -1 and -2 options are selected.
If the input files were ordered according to the collating sequence of the current locale, the lines written will be in the collating sequence of the original lines.
Used only for diagnostic messages.
The following exit values are returned:
- All input files were successfully output as specified.
- An error occurred.
If the input files are not properly presorted, the output of comm might not be useful.
If a file named xpg4 contains a sorted list of the utilities in this specification, a file named xpg3 contains a sorted list of the utilities specified in the X/Open Portability Guide, Issue 3, and a file named svid89 contains a sorted list of the utilities in the System V Interface Definition Third Edition:would print a list of utilities in this specification not specified by either of the other documents;
comm -23 xpg4 xpg3 | comm -23 - svid89would print a list of utilities specified by all three documents; and
comm -12 xpg4 xpg3 | comm -12 - svid89would print a list of utilities specified by both XPG3 and the SVID, but not specified in this specification.
comm -12 xpg3 svid89 | comm -23 - xpg4
cmp, diff, sort, uniq.