# comm

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## 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 the Base Definitions volume
           of POSIX.1‐2017, _Section 7.3.2_ , _LC_COLLATE_) and any lines from the
           input files collate equally but are not identical, _comm_ should
           treat them as different lines but may treat them as being the
           same. If it treats them as different, _comm_ should expect them to
           be ordered according to a further byte-by-byte comparison using
           the collating sequence for the POSIX locale and 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 the Base Definitions volume of
           POSIX.1‐2017, _Section 12.2_ , _Utility Syntax Guidelines_.
    
           The following options shall be supported:
    
           **-1** Suppress the output column of lines unique to _file1_.
    
           **-2** Suppress the output column of lines unique to _file2_.
    
           **-3** Suppress the output column of lines duplicated in _file1_
                     and _file2_.
    


## 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 the Base
                     Definitions volume of POSIX.1‐2017, _Section 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 sequence _comm_
                     expects 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_   Determine the location of message catalogs for the
                     processing of _LC_MESSAGES_.
    


## 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 **-1** option is not selected.
    
           null string
                     The **-1** option 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 **-1** nor the **-2** option is selected.
    
           <tab>     Exactly one of the **-1** and **-2** options is selected.
    
           null string
                     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 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, and _comm_ treated them as different lines, then
           lines written that collate equally but are not identical should 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:
    
            0    All input files were successfully output as specified.
    
           >0    An error occurred.
    


## CONSEQUENCES OF ERRORS



           Default.
    
           _The following sections are informative._
    


## 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, this can affect the behavior of
           _comm_ in the following ways:
    
            *  If _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 _comm_ treats lines as being the same if they collate equally
               and a line from _file1_ collates equally with a line from _file2_
               but is not identical to it, one of the lines is misleadingly
               identified as being in both files and the other is not written
               to the output at all.
    
           Such problems can be avoided by forcing the use of the POSIX
           locale; for example, the following identifies lines in both _file1_
           and _file2_ :
    
               LC_ALL=POSIX sort file1 > file1.posix
               LC_ALL=POSIX sort file2 > file2.posix
               LC_ALL=POSIX comm -12 file1.posix file2.posix | sort
    
           The final _sort_ re-sorts the output of _comm_ according to the
           collating sequence of the original locale. Doing this might be
           difficult if more than one column is output and leading <blank>s
           cannot be ignored.
    


## EXAMPLES



           If a file named **xcu** contains a sorted list of the utilities in
           this volume of POSIX.1‐2017, 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‐2017 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‐2017.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           A future version of this standard may require that if any lines
           from the input files collate equally but are not identical, then
           _comm_ treats them as different lines and expects them to be ordered
           according to a further byte-by-byte comparison using the collating
           sequence for the POSIX locale.
    
           A future version of this standard may require that 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 are ordered according to a further byte-by-byte
           comparison using the collating sequence for the POSIX locale.
    


* * *