isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

join.html (19328B)


      1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved -->
      2 <!DOCTYPE HTML>
      3 <html lang="en">
      4 <head>
      5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0">
      6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 -->
      8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved -->
      9 <title>join</title>
     10 </head>
     11 <body bgcolor="white">
     12 <div class="NAVHEADER">
     13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
     14 <tr class="nav">
     15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/jobs.html" accesskey="P">&lt;&lt;&lt;
     16 Previous</a></td>
     17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
     18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/kill.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
     19 </tr>
     20 </table>
     21 <hr align="left" width="100%"></div>
     22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     23 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     24 IEEE Std 1003.1-2024<br>
     25 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     26 <hr size="2" noshade>
     27 <a name="top" id="top"></a> <a name="join" id="join"></a> <a name="tag_20_63" id="tag_20_63"></a><!-- join -->
     28 <h4 class="mansect"><a name="tag_20_63_01" id="tag_20_63_01"></a>NAME</h4>
     29 <blockquote>join — relational database operator</blockquote>
     30 <h4 class="mansect"><a name="tag_20_63_02" id="tag_20_63_02"></a>SYNOPSIS</h4>
     31 <blockquote class="synopsis">
     32 <p><code><tt>join</tt> <b>[</b><tt>-a</tt> <i>file_number</i><tt>|-v</tt> <i>file_number</i><b>] [</b><tt>-e</tt> <i>string</i><b>]
     33 [</b><tt>-o</tt> <i>list</i><b>] [</b><tt>-t</tt> <i>char</i><b>]<br></b> <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>
     34 <b>[</b><tt>-1</tt> <i>field</i><b>] [</b><tt>-2</tt> <i>field</i><b>]</b> <i>file1 file2</i></code></p>
     35 </blockquote>
     36 <h4 class="mansect"><a name="tag_20_63_03" id="tag_20_63_03"></a>DESCRIPTION</h4>
     37 <blockquote>
     38 <p>The <i>join</i> utility shall perform an equality join on the files <i>file1</i> and <i>file2</i>. The joined files shall be
     39 written to the standard output.</p>
     40 <p>The join field is a field in each file on which the files are compared. The <i>join</i> utility shall write one line in the
     41 output for each pair of lines in <i>file1</i> and <i>file2</i> that have join fields that collate equally. The output line by
     42 default shall consist of the join field, then the remaining fields from <i>file1</i>, then the remaining fields from <i>file2</i>.
     43 This format can be changed by using the <b>-o</b> option (see below). The <b>-a</b> option can be used to add unmatched lines to
     44 the output. The <b>-v</b> option can be used to output only unmatched lines.</p>
     45 <p>The files <i>file1</i> and <i>file2</i> shall be ordered in the collating sequence of <a href=
     46 "../utilities/sort.html"><i>sort</i></a> <b>-b</b> on the fields on which they shall be joined, by default the first in each line.
     47 All selected output shall be written in the same collating sequence.</p>
     48 <p>The default input field separators shall be &lt;blank&gt; characters. In this case, multiple separators shall count as one field
     49 separator, and leading separators shall be ignored. The default output field separator shall be a &lt;space&gt;.</p>
     50 <p>The field separator and collating sequence can be changed by using the <b>-t</b> option (see below).</p>
     51 <p>If the same key appears more than once in either file, all combinations of the set of remaining fields in <i>file1</i> and the
     52 set of remaining fields in <i>file2</i> are output in the order of the lines encountered.</p>
     53 <p>If the input files are not in the appropriate collating sequence, the results are unspecified.</p>
     54 </blockquote>
     55 <h4 class="mansect"><a name="tag_20_63_04" id="tag_20_63_04"></a>OPTIONS</h4>
     56 <blockquote>
     57 <p>The <i>join</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     58 Guidelines</i></a> .</p>
     59 <p>The following options shall be supported:</p>
     60 <dl compact>
     61 <dd></dd>
     62 <dt><b>-a&nbsp;</b><i>file_number</i></dt>
     63 <dd><br>
     64 Produce a line for each unpairable line in file <i>file_number</i>, where <i>file_number</i> is 1 or 2, in addition to the default
     65 output. If both <b>-a</b>1 and <b>-a</b>2 are specified, all unpairable lines shall be output.</dd>
     66 <dt><b>-e&nbsp;</b><i>string</i></dt>
     67 <dd>Replace empty output fields in the list selected by <b>-o</b> with the string <i>string</i>.</dd>
     68 <dt><b>-o&nbsp;</b><i>list</i></dt>
     69 <dd>Construct the output line to comprise the fields specified in <i>list</i>, each element of which shall have one of the
     70 following two forms:
     71 <ol>
     72 <li>
     73 <p><i>file_number.field</i>, where <i>file_number</i> is a file number and <i>field</i> is a decimal integer field number</p>
     74 </li>
     75 <li>
     76 <p>0 (zero), representing the join field</p>
     77 </li>
     78 </ol>
     79 <p>The elements of <i>list</i> shall be either &lt;comma&gt;-separated or &lt;blank&gt;-separated, as specified in Guideline 8 of
     80 XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a> . The fields specified by <i>list</i>
     81 shall be written for all selected output lines. Fields selected by <i>list</i> that do not appear in the input shall be treated as
     82 empty output fields. (See the <b>-e</b> option.) Only specifically requested fields shall be written. The application shall ensure
     83 that <i>list</i> is a single command line argument.</p>
     84 </dd>
     85 <dt><b>-t&nbsp;</b><i>char</i></dt>
     86 <dd>Use character <i>char</i> as a separator, for both input and output. Every appearance of <i>char</i> in a line shall be
     87 significant. When this option is specified, the collating sequence shall be the same as <a href=
     88 "../utilities/sort.html"><i>sort</i></a> without the <b>-b</b> option.</dd>
     89 <dt><b>-v&nbsp;</b><i>file_number</i></dt>
     90 <dd><br>
     91 Instead of the default output, produce a line only for each unpairable line in <i>file_number</i>, where <i>file_number</i> is 1 or
     92 2. If both <b>-v</b>1 and <b>-v</b>2 are specified, all unpairable lines shall be output.</dd>
     93 <dt><b>-1&nbsp;</b><i>field</i></dt>
     94 <dd>Join on the <i>field</i>th field of file 1. Fields are decimal integers starting with 1.</dd>
     95 <dt><b>-2&nbsp;</b><i>field</i></dt>
     96 <dd>Join on the <i>field</i>th field of file 2. Fields are decimal integers starting with 1.</dd>
     97 </dl>
     98 </blockquote>
     99 <h4 class="mansect"><a name="tag_20_63_05" id="tag_20_63_05"></a>OPERANDS</h4>
    100 <blockquote>
    101 <p>The following operands shall be supported:</p>
    102 <dl compact>
    103 <dd></dd>
    104 <dt><i>file1</i>,&nbsp;<i>file2</i></dt>
    105 <dd>A pathname of a file to be joined. If either of the <i>file1</i> or <i>file2</i> operands is <tt>'-'</tt>, the standard input
    106 shall be used in its place.</dd>
    107 </dl>
    108 </blockquote>
    109 <h4 class="mansect"><a name="tag_20_63_06" id="tag_20_63_06"></a>STDIN</h4>
    110 <blockquote>
    111 <p>The standard input shall be used only if the <i>file1</i> or <i>file2</i> operand is <tt>'-'</tt>. See the INPUT FILES
    112 section.</p>
    113 </blockquote>
    114 <h4 class="mansect"><a name="tag_20_63_07" id="tag_20_63_07"></a>INPUT FILES</h4>
    115 <blockquote>
    116 <p>The input files shall be text files.</p>
    117 </blockquote>
    118 <h4 class="mansect"><a name="tag_20_63_08" id="tag_20_63_08"></a>ENVIRONMENT VARIABLES</h4>
    119 <blockquote>
    120 <p>The following environment variables shall affect the execution of <i>join</i>:</p>
    121 <dl compact>
    122 <dd></dd>
    123 <dt><i>LANG</i></dt>
    124 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    125 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    126 variables used to determine the values of locale categories.)</dd>
    127 <dt><i>LC_ALL</i></dt>
    128 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    129 <dt><i>LC_COLLATE</i></dt>
    130 <dd><br>
    131 Determine the locale of the collating sequence <i>join</i> expects to have been used when the input files were sorted.</dd>
    132 <dt><i>LC_CTYPE</i></dt>
    133 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    134 opposed to multi-byte characters in arguments and input files).</dd>
    135 <dt><i>LC_MESSAGES</i></dt>
    136 <dd><br>
    137 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
    138 <dt><i>NLSPATH</i></dt>
    139 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    140 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    141 "0"></dd>
    142 </dl>
    143 </blockquote>
    144 <h4 class="mansect"><a name="tag_20_63_09" id="tag_20_63_09"></a>ASYNCHRONOUS EVENTS</h4>
    145 <blockquote>
    146 <p>Default.</p>
    147 </blockquote>
    148 <h4 class="mansect"><a name="tag_20_63_10" id="tag_20_63_10"></a>STDOUT</h4>
    149 <blockquote>
    150 <p>The <i>join</i> utility output shall be a concatenation of selected character fields. When the <b>-o</b> option is not
    151 specified, the output shall be:</p>
    152 <pre>
    153 <tt>"%s%s%s\n", &lt;</tt><i>join field</i><tt>&gt;, &lt;</tt><i>other file1 fields</i><tt>&gt;,
    154     &lt;</tt><i>other file2 fields</i><tt>&gt;
    155 </tt></pre>
    156 <p>If the join field is not the first field in a file, the &lt;<i>other&nbsp;file&nbsp;fields</i>&gt; for that file shall be:</p>
    157 <pre>
    158 <tt>&lt;</tt><i>fields preceding join field</i><tt>&gt;, &lt;</tt><i>fields following join field</i><tt>&gt;
    159 </tt></pre>
    160 <p>When the <b>-o</b> option is specified, the output format shall be:</p>
    161 <pre>
    162 <tt>"%s\n", &lt;</tt><i>concatenation of fields</i><tt>&gt;
    163 </tt></pre>
    164 <p>where the concatenation of fields is described by the <b>-o</b> option, above.</p>
    165 <p>For either format, each field (except the last) shall be written with its trailing separator character. If the separator is the
    166 default (&lt;blank&gt; characters), a single &lt;space&gt; shall be written after each field (except the last).</p>
    167 </blockquote>
    168 <h4 class="mansect"><a name="tag_20_63_11" id="tag_20_63_11"></a>STDERR</h4>
    169 <blockquote>
    170 <p>The standard error shall be used only for diagnostic messages.</p>
    171 </blockquote>
    172 <h4 class="mansect"><a name="tag_20_63_12" id="tag_20_63_12"></a>OUTPUT FILES</h4>
    173 <blockquote>
    174 <p>None.</p>
    175 </blockquote>
    176 <h4 class="mansect"><a name="tag_20_63_13" id="tag_20_63_13"></a>EXTENDED DESCRIPTION</h4>
    177 <blockquote>
    178 <p>None.</p>
    179 </blockquote>
    180 <h4 class="mansect"><a name="tag_20_63_14" id="tag_20_63_14"></a>EXIT STATUS</h4>
    181 <blockquote>
    182 <p>The following exit values shall be returned:</p>
    183 <dl compact>
    184 <dd></dd>
    185 <dt>&nbsp;0</dt>
    186 <dd>All input files were output successfully.</dd>
    187 <dt>&gt;0</dt>
    188 <dd>An error occurred.</dd>
    189 </dl>
    190 </blockquote>
    191 <h4 class="mansect"><a name="tag_20_63_15" id="tag_20_63_15"></a>CONSEQUENCES OF ERRORS</h4>
    192 <blockquote>
    193 <p>Default.</p>
    194 </blockquote>
    195 <hr>
    196 <div class="box"><em>The following sections are informative.</em></div>
    197 <h4 class="mansect"><a name="tag_20_63_16" id="tag_20_63_16"></a>APPLICATION USAGE</h4>
    198 <blockquote>
    199 <p>Pathnames consisting of numeric digits or of the form <i>string.string</i> should not be specified directly following the
    200 <b>-o</b> list.</p>
    201 <p>If the collating sequence of the current locale does not have a total ordering of all characters (see XBD <a href=
    202 "../basedefs/V1_chap07.html#tag_07_03_02"><i>7.3.2 LC_COLLATE</i></a> ), <i>join</i> treats fields that collate equally but are not
    203 identical as being the same. If this behavior is not desired, it can be avoided by forcing the use of the POSIX locale (although
    204 this means re-sorting the input files into the POSIX locale collating sequence.)</p>
    205 <p>When using <i>join</i> to process pathnames, it is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to
    206 POSIX or C in the environment, since pathnames can contain byte sequences that do not form valid characters in some locales, in
    207 which case the utility's behavior would be undefined. In the POSIX locale each byte is a valid single-byte character, and therefore
    208 this problem is avoided.</p>
    209 </blockquote>
    210 <h4 class="mansect"><a name="tag_20_63_17" id="tag_20_63_17"></a>EXAMPLES</h4>
    211 <blockquote>
    212 <p>The <b>-o</b> 0 field essentially selects the union of the join fields. For example, given file <b>phone</b>:</p>
    213 <pre>
    214 <tt>!Name           Phone Number
    215 Don             +1 123-456-7890
    216 Hal             +1 234-567-8901
    217 Yasushi         +2 345-678-9012
    218 </tt></pre>
    219 <p>and file <b>fax</b>:</p>
    220 <pre>
    221 <tt>!Name           Fax Number
    222 Don             +1 123-456-7899
    223 Keith           +1 456-789-0122
    224 Yasushi         +2 345-678-9011
    225 </tt></pre>
    226 <p>(where the large expanses of white space are meant to each represent a single &lt;tab&gt;), the command:</p>
    227 <pre>
    228 <tt>join -t "&lt;tab&gt;" -a 1 -a 2 -e '(unknown)' -o 0,1.2,2.2 phone fax
    229 </tt></pre>
    230 <p>(where <tt>&lt;tab&gt;</tt> is a literal &lt;tab&gt; character) would produce:</p>
    231 <pre>
    232 <tt>!Name           Phone Number            Fax Number
    233 Don             +1 123-456-7890         +1 123-456-7899
    234 Hal             +1 234-567-8901         (unknown)
    235 Keith           (unknown)               +1 456-789-0122
    236 Yasushi         +2 345-678-9012         +2 345-678-9011
    237 </tt></pre>
    238 <p>Multiple instances of the same key will produce combinatorial results. The following:</p>
    239 <pre>
    240 <tt>fa:
    241     a x
    242     a y
    243     a z
    244 fb:
    245     a p
    246 </tt></pre>
    247 <p>will produce:</p>
    248 <pre>
    249 <tt>a x p
    250 a y p
    251 a z p
    252 </tt></pre>
    253 <p>And the following:</p>
    254 <pre>
    255 <tt>fa:
    256     a b c
    257     a d e
    258 fb:
    259     a w x
    260     a y z
    261     a o p
    262 </tt></pre>
    263 <p>will produce:</p>
    264 <pre>
    265 <tt>a b c w x
    266 a b c y z
    267 a b c o p
    268 a d e w x
    269 a d e y z
    270 a d e o p
    271 </tt></pre></blockquote>
    272 <h4 class="mansect"><a name="tag_20_63_18" id="tag_20_63_18"></a>RATIONALE</h4>
    273 <blockquote>
    274 <p>The <b>-e</b> option is only effective when used with <b>-o</b> because, unless specific fields are identified using <b>-o</b>,
    275 <i>join</i> is not aware of what fields might be empty. The exception to this is the join field, but identifying an empty join
    276 field with the <b>-e</b> string is not historical practice and some scripts might break if this were changed.</p>
    277 <p>The 0 field in the <b>-o</b> list was adopted from the Tenth Edition version of <i>join</i> to satisfy international objections
    278 that the <i>join</i> in the base documents for IEEE&nbsp;Std&nbsp;1003.2-1992 did not support the &quot;full join&quot; or &quot;outer join&quot;
    279 described in relational database literature. Although it has been possible to include a join field in the output (by default, or by
    280 field number using <b>-o</b>), the join field could not be included for an unpaired line selected by <b>-a</b>. The <b>-o</b> 0
    281 field essentially selects the union of the join fields.</p>
    282 <p>This sort of outer join was not possible with the <i>join</i> commands in the base documents for IEEE&nbsp;Std&nbsp;1003.2-1992.
    283 The <b>-o</b> 0 field was chosen because it is an upwards-compatible change for applications. An alternative was considered: have
    284 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
    285 for unmatched lines). This was not adopted because it would break some historical applications.</p>
    286 <p>The ability to specify <i>file2</i> as <b>-</b> is not historical practice; it was added for completeness.</p>
    287 <p>The <b>-v</b> option is not historical practice, but was considered necessary because it permitted the writing of <i>only</i>
    288 those lines that do not match on the join field, as opposed to the <b>-a</b> option, which prints both lines that do and do not
    289 match. This additional facility is parallel with the <b>-v</b> option of <a href="../utilities/grep.html"><i>grep</i></a>.</p>
    290 <p>Some historical implementations have been encountered where a blank line in one of the input files was considered to be the end
    291 of the file; the description in this volume of POSIX.1-2024 does not cite this as an allowable case.</p>
    292 <p>Earlier versions of this standard allowed <b>-j</b>, <b>-j1</b>, <b>-j2</b> options, and a form of the <b>-o</b> option that
    293 allowed the <i>list</i> option-argument to be multiple arguments. These forms are no longer specified by POSIX.1-2024 but may be
    294 present in some implementations.</p>
    295 </blockquote>
    296 <h4 class="mansect"><a name="tag_20_63_19" id="tag_20_63_19"></a>FUTURE DIRECTIONS</h4>
    297 <blockquote>
    298 <p>None.</p>
    299 </blockquote>
    300 <h4 class="mansect"><a name="tag_20_63_20" id="tag_20_63_20"></a>SEE ALSO</h4>
    301 <blockquote>
    302 <p><a href="../utilities/awk.html#"><i>awk</i></a> , <a href="../utilities/comm.html#"><i>comm</i></a> , <a href=
    303 "../utilities/sort.html#"><i>sort</i></a> , <a href="../utilities/uniq.html#"><i>uniq</i></a></p>
    304 <p>XBD <a href="../basedefs/V1_chap07.html#tag_07_03_02"><i>7.3.2 LC_COLLATE</i></a> , <a href=
    305 "../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2
    306 Utility Syntax Guidelines</i></a></p>
    307 </blockquote>
    308 <h4 class="mansect"><a name="tag_20_63_21" id="tag_20_63_21"></a>CHANGE HISTORY</h4>
    309 <blockquote>
    310 <p>First released in Issue 2.</p>
    311 </blockquote>
    312 <h4 class="mansect"><a name="tag_20_63_22" id="tag_20_63_22"></a>Issue 6</h4>
    313 <blockquote>
    314 <p>The obsolescent <b>-j</b> options and the multi-argument <b>-o</b> option are removed in this version.</p>
    315 <p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
    316 </blockquote>
    317 <h4 class="mansect"><a name="tag_20_63_23" id="tag_20_63_23"></a>Issue 7</h4>
    318 <blockquote>
    319 <p>Austin Group Interpretation 1003.1-2001 #027 is applied.</p>
    320 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    321 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0109 [963], XCU/TC2-2008/0110 [663], XCU/TC2-2008/0111 [971], and
    322 XCU/TC2-2008/0112 [885] are applied.</p>
    323 </blockquote>
    324 <h4 class="mansect"><a name="tag_20_63_24" id="tag_20_63_24"></a>Issue 8</h4>
    325 <blockquote>
    326 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    327 </blockquote>
    328 <div class="box"><em>End of informative text.</em></div>
    329 <hr>
    330 <p>&nbsp;</p>
    331 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    332 <hr size="2" noshade>
    333 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    334 POSIX™ is a Trademark of The IEEE.<br>
    335 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    336 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    337 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    338 ]</font></center>
    339 <hr size="2" noshade>
    340 <div class="NAVHEADER">
    341 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    342 <tr class="nav">
    343 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/jobs.html" accesskey="P">&lt;&lt;&lt;
    344 Previous</a></td>
    345 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    346 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/kill.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
    347 </tr>
    348 </table>
    349 <hr align="left" width="100%"></div>
    350 </body>
    351 </html>