JOIN(1)                    POSIX Programmer's Manual                   JOIN(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
       join -- relational database operator

SSYYNNOOPPSSIISS
       join [[-a _f_i_l_e___n_u_m_b_e_r|-v _f_i_l_e___n_u_m_b_e_r]] [[-e _s_t_r_i_n_g]] [[-o _l_i_s_t]] [[-t _c_h_a_r]]
           [[-1 _f_i_e_l_d]] [[-2 _f_i_e_l_d]] _f_i_l_e_1 _f_i_l_e_2

DDEESSCCRRIIPPTTIIOONN
       The _j_o_i_n utility shall perform an equality join on the files _f_i_l_e_1 and
       _f_i_l_e_2.  The joined files shall be written to the standard output.

       The join field is a field in each file on which the files are compared.
       The _j_o_i_n utility shall write one line in the output for each pair of
       lines in _f_i_l_e_1 and _f_i_l_e_2 that have identical join fields. The output
       line by default shall consist of the join field, then the remaining
       fields from _f_i_l_e_1, then the remaining fields from _f_i_l_e_2.  This format
       can be changed by using the --oo option (see below). The --aa option can be
       used to add unmatched lines to the output. The --vv option can be used to
       output only unmatched lines.

       The files _f_i_l_e_1 and _f_i_l_e_2 shall be ordered in the collating sequence of
       _s_o_r_t --bb on the fields on which they shall be joined, by default the
       first in each line. All selected output shall be written in the same
       collating sequence.

       The default input field separators shall be <blank> characters. In this
       case, multiple separators shall count as one field separator, and
       leading separators shall be ignored. The default output field separator
       shall be a <space>.

       The field separator and collating sequence can be changed by using the
       --tt option (see below).

       If the same key appears more than once in either file, all combinations
       of the set of remaining fields in _f_i_l_e_1 and the set of remaining fields
       in _f_i_l_e_2 are output in the order of the lines encountered.

       If the input files are not in the appropriate collating sequence, the
       results are unspecified.

OOPPTTIIOONNSS
       The _j_o_i_n utility shall conform to the Base Definitions volume of
       POSIX.1-2008, _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:

       --aa _f_i_l_e___n_u_m_b_e_r
                 Produce a line for each unpairable line in file _f_i_l_e___n_u_m_b_e_r,
                 where _f_i_l_e___n_u_m_b_e_r is 1 or 2, in addition to the default
                 output. If both --aa1 and --aa2 are specified, all unpairable
                 lines shall be output.

       --ee _s_t_r_i_n_g Replace empty output fields in the list selected by --oo with
                 the string _s_t_r_i_n_g.

       --oo _l_i_s_t   Construct the output line to comprise the fields specified in
                 _l_i_s_t, each element of which shall have one of the following
                 two forms:

                  1. _f_i_l_e___n_u_m_b_e_r_._f_i_e_l_d, where _f_i_l_e___n_u_m_b_e_r is a file number and
                     _f_i_e_l_d is a decimal integer field number

                  2. 0 (zero), representing the join field

                 The elements of _l_i_s_t shall be either <comma>-separated or
                 <blank>-separated, as specified in Guideline 8 of the Base
                 Definitions volume of POSIX.1-2008, _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 fields specified by _l_i_s_t shall be
                 written for all selected output lines. Fields selected by
                 _l_i_s_t that do not appear in the input shall be treated as
                 empty output fields. (See the --ee option.) Only specifically
                 requested fields shall be written. The application shall
                 ensure that _l_i_s_t is a single command line argument.

       --tt _c_h_a_r   Use character _c_h_a_r as a separator, for both input and output.
                 Every appearance of _c_h_a_r in a line shall be significant. When
                 this option is specified, the collating sequence shall be the
                 same as _s_o_r_t without the --bb option.

       --vv _f_i_l_e___n_u_m_b_e_r
                 Instead of the default output, produce a line only for each
                 unpairable line in _f_i_l_e___n_u_m_b_e_r, where _f_i_l_e___n_u_m_b_e_r is 1 or 2.
                 If both --vv1 and --vv2 are specified, all unpairable lines shall
                 be output.

       --11 _f_i_e_l_d  Join on the _f_i_e_l_dth field of file 1. Fields are decimal
                 integers starting with 1.

       --22 _f_i_e_l_d  Join on the _f_i_e_l_dth field of file 2. Fields are decimal
                 integers starting with 1.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _f_i_l_e_1, _f_i_l_e_2
                 A pathname of a file to be joined. If either of the _f_i_l_e_1 or
                 _f_i_l_e_2 operands is ''--'', the standard input shall be used in
                 its place.

SSTTDDIINN
       The standard input shall be used only if the _f_i_l_e_1 or _f_i_l_e_2 operand is
       ''--''.  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 _j_o_i_n:

       _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-2008, _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 of the collating sequence _j_o_i_n 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 _j_o_i_n utility output shall be a concatenation of selected character
       fields.  When the --oo option is not specified, the output shall be:

           ""%%ss%%ss%%ss\\nn"",, <<_j_o_i_n _f_i_e_l_d>, <_o_t_h_e_r _f_i_l_e_1 _f_i_e_l_d_s>,
               <_o_t_h_e_r _f_i_l_e_2 _f_i_e_l_d_s>

       If the join field is not the first field in a file, the
       <_o_t_h_e_r _f_i_l_e _f_i_e_l_d_s> for that file shall be:

           <<_f_i_e_l_d_s _p_r_e_c_e_d_i_n_g _j_o_i_n _f_i_e_l_d>, <_f_i_e_l_d_s _f_o_l_l_o_w_i_n_g _j_o_i_n _f_i_e_l_d>

       When the --oo option is specified, the output format shall be:

           ""%%ss\\nn"",, <<_c_o_n_c_a_t_e_n_a_t_i_o_n _o_f _f_i_e_l_d_s>

       where the concatenation of fields is described by the --oo option, above.

       For either format, each field (except the last) shall be written with
       its trailing separator character. If the separator is the default
       (<blank> characters), a single <space> shall be written after each
       field (except the last).

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 output successfully.

       >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
       Pathnames consisting of numeric digits or of the form _s_t_r_i_n_g_._s_t_r_i_n_g
       should not be specified directly following the --oo list.

EEXXAAMMPPLLEESS
       The --oo 0 field essentially selects the union of the join fields. For
       example, given file pphhoonnee:

           !!NNaammee           PPhhoonnee NNuummbbeerr
           DDoonn             ++11 112233--445566--77889900
           HHaall             ++11 223344--556677--88990011
           YYaassuusshhii         ++22 334455--667788--99001122

       and file ffaaxx:

           !!NNaammee           FFaaxx NNuummbbeerr
           DDoonn             ++11 112233--445566--77889999
           KKeeiitthh           ++11 445566--778899--00112222
           YYaassuusshhii         ++22 334455--667788--99001111

       (where the large expanses of white space are meant to each represent a
       single <tab>), the command:

           jjooiinn --tt ""<<ttaabb>>"" --aa 11 --aa 22 --ee ''((uunnkknnoowwnn))'' --oo 00,,11..22,,22..22 pphhoonnee ffaaxx

       would produce:

           !!NNaammee           PPhhoonnee NNuummbbeerr            FFaaxx NNuummbbeerr
           DDoonn             ++11 112233--445566--77889900         ++11 112233--445566--77889999
           HHaall             ++11 223344--556677--88990011         ((uunnkknnoowwnn))
           KKeeiitthh           ((uunnkknnoowwnn))               ++11 445566--778899--00112222
           YYaassuusshhii         ++22 334455--667788--99001122         ++22 334455--667788--99001111

       Multiple instances of the same key will produce combinatorial results.
       The following:

           ffaa::
               aa xx
               aa yy
               aa zz
           ffbb::
               aa pp

       will produce:

           aa xx pp
           aa yy pp
           aa zz pp

       And the following:

           ffaa::
               aa bb cc
               aa dd ee
           ffbb::
               aa ww xx
               aa yy zz
               aa oo pp

       will produce:

           aa bb cc ww xx
           aa bb cc yy zz
           aa bb cc oo pp
           aa dd ee ww xx
           aa dd ee yy zz
           aa dd ee oo pp

RRAATTIIOONNAALLEE
       The --ee option is only effective when used with --oo because, unless
       specific fields are identified using --oo, _j_o_i_n is not aware of what
       fields might be empty. The exception to this is the join field, but
       identifying an empty join field with the --ee string is not historical
       practice and some scripts might break if this were changed.

       The 0 field in the --oo list was adopted from the Tenth Edition version
       of _j_o_i_n to satisfy international objections that the _j_o_i_n in the base
       documents does not support the ``full join'' or ``outer join''
       described in relational database literature. Although it has been
       possible to include a join field in the output (by default, or by field
       number using --oo), the join field could not be included for an unpaired
       line selected by --aa.  The --oo 0 field essentially selects the union of
       the join fields.

       This sort of outer join was not possible with the _j_o_i_n commands in the
       base documents. The --oo 0 field was chosen because it is an upwards-
       compatible change for applications. An alternative was considered: have
       the join field represent the union of the fields in the files (where
       they are identical for matched lines, and one or both are null for
       unmatched lines). This was not adopted because it would break some
       historical applications.

       The ability to specify _f_i_l_e_2 as -- is not historical practice; it was
       added for completeness.

       The --vv option is not historical practice, but was considered necessary
       because it permitted the writing of _o_n_l_y those lines that do not match
       on the join field, as opposed to the --aa option, which prints both lines
       that do and do not match. This additional facility is parallel with the
       --vv option of _g_r_e_p.

       Some historical implementations have been encountered where a blank
       line in one of the input files was considered to be the end of the
       file; the description in this volume of POSIX.1-2008 does not cite this
       as an allowable case.

       Earlier versions of this standard allowed --jj, --jj11, --jj22 options, and a
       form of the --oo option that allowed the _l_i_s_t option-argument to be
       multiple arguments. These forms are no longer specified by POSIX.1-2008
       but may be present in some implementations.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _a_w_k, _c_o_m_m, _s_o_r_t, _u_n_i_q

       The Base Definitions volume of POSIX.1-2008, _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, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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.unix.org/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                  2013                              JOIN(1)
