NAME
comm — select or
reject lines common to two files
SYNOPSIS
comm |
[-123] file1
file2 |
DESCRIPTION
The comm utility shall 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.
If the collating sequence of the current locale does not have a
total ordering of all characters (see XBD V1_chap07(7))
and any lines from the input files collate equally but are not identical,
comm shall treat them as different lines and shall
expect them to be ordered according to a further byte-by-byte comparison
using the collating sequence for the POSIX locale; if they are not ordered
in this way, the output of comm can identify such
lines as being both unique to file1 and unique to
file2 instead of being in both files.
OPTIONS
The comm utility shall conform to XBD
V1_chap12(7).
The following options shall be supported:
OPERANDS
The following operands shall be supported:
- file1
- A pathname of the first file to be compared. If file1 is '-' , the standard input shall be used.
- file2
- A pathname of the second file to be compared. If file2 is '-' , the standard input shall be 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.
STDIN
The standard input shall be used only if one of the file1 or file2 operands refers to standard input. See the INPUT FILES section.
INPUT FILES
The input files shall be text files.
ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of
comm:
LANG- Provide a default value for the internationalization variables that are unset or null. (See XBD 8.2 Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
LC_ALL- If set to a non-empty string value, override the values of all the other internationalization variables.
LC_COLLATE-
Determine the locale for the collating sequencecommexpects to have been used when the input files were sorted. LC_CTYPE- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files).
LC_MESSAGES-
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH- [
XSI] Determine the location of messages objects and message catalogs.
ASYNCHRONOUS EVENTS
Default.
STDOUT
The comm utility shall produce output
depending on the options selected. If the -1,
-2, and -3 options are all
selected, comm shall write nothing to standard
output.
If the -1 option is not selected, lines
contained only in file1 shall be written using the
format:
"%s\n", <line in file1>
If the -2 option is not selected, lines
contained only in file2 are written using the format:
"%s%s\n", <lead>, <line in file2>
where the string < lead > is as follows:
- <tab>
- The
-1option is not selected. - null string
- The
-1option is selected.
If the -3 option is not selected, lines
contained in both files shall be written using the format:
"%s%s\n", <lead>, <line in both>
where the string < lead > is as follows:
- <tab><tab>
- Neither the
-1nor the-2option is selected. - <tab>
- Exactly one of the
-1and-2options is selected. - null string
- Both the
-1and-2options are selected.
If the input files were ordered according to the collating sequence of the current locale, the lines written shall be in the collating sequence of the current locale. If the input files contained any lines that collated equally but were not identical and within each file those lines were ordered according to a further byte-by-byte comparison using the collating sequence for the POSIX locale, then lines written that collate equally but are not identical shall be ordered according to a further byte-by-byte comparison using the collating sequence for the POSIX locale.
STDERR
The standard error shall be used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The following exit values shall be returned:
CONSEQUENCES OF ERRORS
Default.
APPLICATION USAGE
If the input files are not properly presorted, the output of
comm might not be useful.
When using comm to process pathnames, it
is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to
POSIX or C in the environment, since pathnames can contain byte sequences
that do not form valid characters in some locales, in which case the
utility's behavior would be undefined. In the POSIX locale each byte is a
valid single-byte character, and therefore this problem is avoided.
If the collating sequence of the current locale does not have a
total ordering of all characters, since comm treats
lines as being the same only if they are identical, some lines can be
misleadingly identified as being both unique to file1 and
unique to file2 if lines that collate equally but are not
identical are not ordered in the way that comm
expects. If the input does not come from utilities (such as
ls(1) and sort(1)) which provide this
ordering, the problem can be avoided by pre-sorting the input files using
sort(1).
EXAMPLES
If a file named xcu contains a sorted list of the utilities in this volume of POSIX.1-2024, 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:
comm -23 xcu xpg3 | comm -23 - svid89
would print a list of utilities in this volume of POSIX.1-2024 not specified by either of the other documents:
comm -12 xcu xpg3 | comm -12 - svid89
would print a list of utilities specified by all three documents, and:
comm -12 xpg3 svid89 | comm -23 - xcu
would print a list of utilities specified by both XPG3 and the SVID, but not specified in this volume of POSIX.1-2024.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
CHANGE HISTORY
First released in Issue 2.
Issue 6
The normative text is reworded to avoid use of the term "must" for application requirements.
Issue 7
POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0076 [963], XCU/TC2-2008/0077 [663], and XCU/TC2-2008/0078 [963] are applied.
Issue 8
Austin Group Defect 1070 is applied, changing the requirements when any lines from the input files collate equally but are not identical.
Austin Group Defect 1122 is applied, changing the description of NLSPATH .