COMM(1)                    POSIX Programmer's Manual                   COMM(1)



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

NNAAMMEE
       comm -- select or reject lines common to two files

SSYYNNOOPPSSIISS
       comm [[-123]] _f_i_l_e_1 _f_i_l_e_2

DDEESSCCRRIIPPTTIIOONN
       The _c_o_m_m utility shall read _f_i_l_e_1 and _f_i_l_e_2, which should be ordered in
       the current collating sequence, and produce three text columns as
       output: lines only in _f_i_l_e_1, lines only in _f_i_l_e_2, 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, _S_e_c_t_i_o_n _7_._3_._2, _L_C___C_O_L_L_A_T_E) and any lines from the input
       files collate equally but are not identical, _c_o_m_m should treat them as
       different lines but may treat them as being the same. If it treats them
       as different, _c_o_m_m 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
       _c_o_m_m can identify such lines as being both unique to _f_i_l_e_1 and unique
       to _f_i_l_e_2 instead of being in both files.

OOPPTTIIOONNSS
       The _c_o_m_m utility shall conform to the Base Definitions volume of
       POSIX.1-2017, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following options shall be supported:

       --11        Suppress the output column of lines unique to _f_i_l_e_1.

       --22        Suppress the output column of lines unique to _f_i_l_e_2.

       --33        Suppress the output column of lines duplicated in _f_i_l_e_1 and
                 _f_i_l_e_2.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _f_i_l_e_1     A pathname of the first file to be compared. If _f_i_l_e_1 is ''--'',
                 the standard input shall be used.

       _f_i_l_e_2     A pathname of the second file to be compared. If _f_i_l_e_2 is
                 ''--'', the standard input shall be used.

       If both _f_i_l_e_1 and _f_i_l_e_2 refer to standard input or to the same FIFO
       special, block special, or character special file, the results are
       undefined.

SSTTDDIINN
       The standard input shall be used only if one of the _f_i_l_e_1 or _f_i_l_e_2
       operands refers to standard input. See the INPUT FILES section.

IINNPPUUTT FFIILLEESS
       The input files shall be text files.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _c_o_m_m:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2017, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_O_L_L_A_T_E
                 Determine the locale for the collating sequence _c_o_m_m expects
                 to have been used when the input files were sorted.

       _L_C___C_T_Y_P_E  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).

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       The _c_o_m_m utility shall produce output depending on the options
       selected. If the --11, --22, and --33 options are all selected, _c_o_m_m shall
       write nothing to standard output.

       If the --11 option is not selected, lines contained only in _f_i_l_e_1 shall
       be written using the format:


           "%s\n", <_l_i_n_e _i_n _f_i_l_e_1>

       If the --22 option is not selected, lines contained only in _f_i_l_e_2 are
       written using the format:


           "%s%s\n", <_l_e_a_d>, <_l_i_n_e _i_n _f_i_l_e_2>

       where the string <_l_e_a_d> is as follows:

       <tab>     The --11 option is not selected.

       null string
                 The --11 option is selected.

       If the --33 option is not selected, lines contained in both files shall
       be written using the format:


           "%s%s\n", <_l_e_a_d>, <_l_i_n_e _i_n _b_o_t_h>

       where the string <_l_e_a_d> is as follows:

       <tab><tab>
                 Neither the --11 nor the --22 option is selected.

       <tab>     Exactly one of the --11 and --22 options is selected.

       null string
                 Both the --11 and --22 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 _c_o_m_m 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.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    All input files were successfully output as specified.

       >0    An error occurred.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       If the input files are not properly presorted, the output of _c_o_m_m might
       not be useful.

       When using _c_o_m_m 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 _c_o_m_m in the
       following ways:

        *  If _c_o_m_m treats lines as being the same only if they are identical,
           some lines can be misleadingly identified as being both unique to
           _f_i_l_e_1 and unique to _f_i_l_e_2.

        *  If _c_o_m_m treats lines as being the same if they collate equally and
           a line from _f_i_l_e_1 collates equally with a line from _f_i_l_e_2 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 _f_i_l_e_1 and _f_i_l_e_2:


           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 _s_o_r_t re-sorts the output of _c_o_m_m 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.

EEXXAAMMPPLLEESS
       If a file named xxccuu contains a sorted list of the utilities in this
       volume of POSIX.1-2017, a file named xxppgg33 contains a sorted list of the
       utilities specified in the X/Open Portability Guide, Issue 3, and a
       file named ssvviidd8899 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.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       A future version of this standard may require that if any lines from
       the input files collate equally but are not identical, then _c_o_m_m 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.

SSEEEE AALLSSOO
       _c_m_p, _d_i_f_f, _s_o_r_t, _u_n_i_q

       The Base Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _7_._3_._2, _L_C___C_O_L_L_A_T_E,
       _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x
       _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                              COMM(1)
