isposix

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

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

uniq.html (16051B)


      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>uniq</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/unget.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/unlink.html" accesskey="N">Next
     19 &gt;&gt;&gt;</a></td>
     20 </tr>
     21 </table>
     22 <hr align="left" width="100%"></div>
     23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     24 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     25 IEEE Std 1003.1-2024<br>
     26 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     27 <hr size="2" noshade>
     28 <a name="top" id="top"></a> <a name="uniq" id="uniq"></a> <a name="tag_20_138" id="tag_20_138"></a><!-- uniq -->
     29 <h4 class="mansect"><a name="tag_20_138_01" id="tag_20_138_01"></a>NAME</h4>
     30 <blockquote>uniq — report or filter out repeated lines in a file</blockquote>
     31 <h4 class="mansect"><a name="tag_20_138_02" id="tag_20_138_02"></a>SYNOPSIS</h4>
     32 <blockquote class="synopsis">
     33 <p><code><tt>uniq</tt> <b>[</b><tt>-c|-d|-u</tt><b>] [</b><tt>-f</tt> <i>fields</i><b>] [</b><tt>-s</tt> <i>char</i><b>]
     34 [</b><i>input_file</i> <b>[</b><i>output_file</i><b>]]</b></code></p>
     35 </blockquote>
     36 <h4 class="mansect"><a name="tag_20_138_03" id="tag_20_138_03"></a>DESCRIPTION</h4>
     37 <blockquote>
     38 <p>The <i>uniq</i> utility shall read an input file comparing adjacent lines, and write one copy of each input line on the output.
     39 The second and succeeding copies of repeated adjacent input lines shall not be written. The trailing &lt;newline&gt; of each line
     40 in the input shall be ignored when doing comparisons.</p>
     41 <p>Repeated lines in the input shall not be detected if they are not adjacent.</p>
     42 </blockquote>
     43 <h4 class="mansect"><a name="tag_20_138_04" id="tag_20_138_04"></a>OPTIONS</h4>
     44 <blockquote>
     45 <p>The <i>uniq</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     46 Guidelines</i></a> , except that <tt>'+'</tt> may be recognized as an option delimiter as well as <tt>'-'</tt>.</p>
     47 <p>The following options shall be supported:</p>
     48 <dl compact>
     49 <dd></dd>
     50 <dt><b>-c</b></dt>
     51 <dd>Precede each output line with a count of the number of times the line occurred in the input.</dd>
     52 <dt><b>-d</b></dt>
     53 <dd>Suppress the writing of lines that are not repeated in the input.</dd>
     54 <dt><b>-f&nbsp;</b><i>fields</i></dt>
     55 <dd>Ignore the first <i>fields</i> fields on each input line when doing comparisons, where <i>fields</i> is a positive decimal
     56 integer. A field is the maximal string matched by the basic regular expression:
     57 <pre>
     58 <tt>[[:blank:]]*[^[:blank:]]*
     59 </tt></pre>
     60 <p>If the <i>fields</i> option-argument specifies more fields than appear on an input line, a null string shall be used for
     61 comparison.</p>
     62 </dd>
     63 <dt><b>-s&nbsp;</b><i>chars</i></dt>
     64 <dd>Ignore the first <i>chars</i> characters when doing comparisons, where <i>chars</i> shall be a positive decimal integer. If
     65 specified in conjunction with the <b>-f</b> option, the first <i>chars</i> characters after the first <i>fields</i> fields shall be
     66 ignored. If the <i>chars</i> option-argument specifies more characters than remain on an input line, a null string shall be used
     67 for comparison.</dd>
     68 <dt><b>-u</b></dt>
     69 <dd>Suppress the writing of lines that are repeated in the input.</dd>
     70 </dl>
     71 </blockquote>
     72 <h4 class="mansect"><a name="tag_20_138_05" id="tag_20_138_05"></a>OPERANDS</h4>
     73 <blockquote>
     74 <p>The following operands shall be supported:</p>
     75 <dl compact>
     76 <dd></dd>
     77 <dt><i>input_file</i></dt>
     78 <dd>A pathname of the input file. If the <i>input_file</i> operand is not specified, or if the <i>input_file</i> is <tt>'-'</tt>,
     79 the standard input shall be used.</dd>
     80 <dt><i>output_file</i></dt>
     81 <dd>A pathname of the output file. If the <i>output_file</i> operand is not specified, the standard output shall be used. The
     82 results are unspecified if the file named by <i>output_file</i> is the file named by <i>input_file</i>.</dd>
     83 </dl>
     84 </blockquote>
     85 <h4 class="mansect"><a name="tag_20_138_06" id="tag_20_138_06"></a>STDIN</h4>
     86 <blockquote>
     87 <p>The standard input shall be used only if no <i>input_file</i> operand is specified or if <i>input_file</i> is <tt>'-'</tt>. See
     88 the INPUT FILES section.</p>
     89 </blockquote>
     90 <h4 class="mansect"><a name="tag_20_138_07" id="tag_20_138_07"></a>INPUT FILES</h4>
     91 <blockquote>
     92 <p>The input file shall be a text file.</p>
     93 </blockquote>
     94 <h4 class="mansect"><a name="tag_20_138_08" id="tag_20_138_08"></a>ENVIRONMENT VARIABLES</h4>
     95 <blockquote>
     96 <p>The following environment variables shall affect the execution of <i>uniq</i>:</p>
     97 <dl compact>
     98 <dd></dd>
     99 <dt><i>LANG</i></dt>
    100 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    101 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    102 variables used to determine the values of locale categories.)</dd>
    103 <dt><i>LC_ALL</i></dt>
    104 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    105 <dt><i>LC_CTYPE</i></dt>
    106 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    107 opposed to multi-byte characters in arguments and input files) and which characters constitute a &lt;blank&gt; in the current
    108 locale.</dd>
    109 <dt><i>LC_MESSAGES</i></dt>
    110 <dd><br>
    111 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
    112 <dt><i>NLSPATH</i></dt>
    113 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    114 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    115 "0"></dd>
    116 </dl>
    117 </blockquote>
    118 <h4 class="mansect"><a name="tag_20_138_09" id="tag_20_138_09"></a>ASYNCHRONOUS EVENTS</h4>
    119 <blockquote>
    120 <p>Default.</p>
    121 </blockquote>
    122 <h4 class="mansect"><a name="tag_20_138_10" id="tag_20_138_10"></a>STDOUT</h4>
    123 <blockquote>
    124 <p>The standard output shall be used if no <i>output_file</i> operand is specified, and shall be used if the <i>output_file</i>
    125 operand is <tt>'-'</tt> and the implementation treats the <tt>'-'</tt> as meaning standard output. Otherwise, the standard output
    126 shall not be used. See the OUTPUT FILES section.</p>
    127 </blockquote>
    128 <h4 class="mansect"><a name="tag_20_138_11" id="tag_20_138_11"></a>STDERR</h4>
    129 <blockquote>
    130 <p>The standard error shall be used only for diagnostic messages.</p>
    131 </blockquote>
    132 <h4 class="mansect"><a name="tag_20_138_12" id="tag_20_138_12"></a>OUTPUT FILES</h4>
    133 <blockquote>
    134 <p>If the <b>-c</b> option is specified, the output file shall be empty or each line shall be of the form:</p>
    135 <pre>
    136 <tt>"%d %s", &lt;</tt><i>number of duplicates</i><tt>&gt;, &lt;</tt><i>line</i><tt>&gt;
    137 </tt></pre>
    138 <p>otherwise, the output file shall be empty or each line shall be of the form:</p>
    139 <pre>
    140 <tt>"%s", &lt;</tt><i>line</i><tt>&gt;
    141 </tt></pre></blockquote>
    142 <h4 class="mansect"><a name="tag_20_138_13" id="tag_20_138_13"></a>EXTENDED DESCRIPTION</h4>
    143 <blockquote>
    144 <p>None.</p>
    145 </blockquote>
    146 <h4 class="mansect"><a name="tag_20_138_14" id="tag_20_138_14"></a>EXIT STATUS</h4>
    147 <blockquote>
    148 <p>The following exit values shall be returned:</p>
    149 <dl compact>
    150 <dd></dd>
    151 <dt>&nbsp;0</dt>
    152 <dd>Successful completion.</dd>
    153 <dt>&gt;0</dt>
    154 <dd>An error occurred.</dd>
    155 </dl>
    156 </blockquote>
    157 <h4 class="mansect"><a name="tag_20_138_15" id="tag_20_138_15"></a>CONSEQUENCES OF ERRORS</h4>
    158 <blockquote>
    159 <p>Default.</p>
    160 </blockquote>
    161 <hr>
    162 <div class="box"><em>The following sections are informative.</em></div>
    163 <h4 class="mansect"><a name="tag_20_138_16" id="tag_20_138_16"></a>APPLICATION USAGE</h4>
    164 <blockquote>
    165 <p>The <a href="../utilities/sort.html"><i>sort</i></a> utility can be used to cause repeated lines to be adjacent in the input
    166 file.</p>
    167 <p>If the collating sequence of the current locale does not have a total ordering of all characters, the behavior of <tt>sort |
    168 uniq</tt> differs from <tt>sort -u</tt>, as <tt>uniq</tt> treats lines as duplicates only if they are identical, whereas <tt>sort
    169 -u</tt> treats lines as duplicates if they collate equally.</p>
    170 <p>When using <i>uniq</i> to process pathnames, it is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to
    171 POSIX or C in the environment, since pathnames can contain byte sequences that do not form valid characters in some locales, in
    172 which case the utility's behavior would be undefined. In the POSIX locale each byte is a valid single-byte character, and therefore
    173 this problem is avoided.</p>
    174 </blockquote>
    175 <h4 class="mansect"><a name="tag_20_138_17" id="tag_20_138_17"></a>EXAMPLES</h4>
    176 <blockquote>
    177 <p>The following input file data (but flushed left) was used for a test series on <i>uniq</i>:</p>
    178 <pre>
    179 <tt>#01 foo0 bar0 foo1 bar1
    180 #02 bar0 foo1 bar1 foo1
    181 #03 foo0 bar0 foo1 bar1
    182 #04
    183 #05 foo0 bar0 foo1 bar1
    184 #06 foo0 bar0 foo1 bar1
    185 #07 bar0 foo1 bar1 foo0
    186 </tt></pre>
    187 <p>What follows is a series of test invocations of the <i>uniq</i> utility that use a mixture of <i>uniq</i> options against the
    188 input file data. These tests verify the meaning of <i>adjacent</i>. The <i>uniq</i> utility views the input data as a sequence of
    189 strings delimited by <tt>'\n'</tt>. Accordingly, for the <i>fields</i>th member of the sequence, <i>uniq</i> interprets unique or
    190 repeated adjacent lines strictly relative to the <i>fields</i>+1th member.</p>
    191 <ol>
    192 <li>
    193 <p>This first example tests the line counting option, comparing each line of the input file data starting from the second
    194 field:</p>
    195 <pre>
    196 <tt>uniq -c -f 1 uniq_0I.t
    197     1 #01 foo0 bar0 foo1 bar1
    198     1 #02 bar0 foo1 bar1 foo1
    199     1 #03 foo0 bar0 foo1 bar1
    200     1 #04
    201     2 #05 foo0 bar0 foo1 bar1
    202     1 #07 bar0 foo1 bar1 foo0
    203 </tt></pre>
    204 <p>The number <tt>'2'</tt>, prefixing the fifth line of output, signifies that the <i>uniq</i> utility detected a pair of repeated
    205 lines. Given the input data, this can only be true when <i>uniq</i> is run using the <b>-f&nbsp;1</b> option (which shall cause
    206 <i>uniq</i> to ignore the first field on each input line).</p>
    207 </li>
    208 <li>
    209 <p>The second example tests the option to suppress unique lines, comparing each line of the input file data starting from the
    210 second field:</p>
    211 <pre>
    212 <tt>uniq -d -f 1 uniq_0I.t
    213 #05 foo0 bar0 foo1 bar1
    214 </tt></pre></li>
    215 <li>
    216 <p>This test suppresses repeated lines, comparing each line of the input file data starting from the second field:</p>
    217 <pre>
    218 <tt>uniq -u -f 1 uniq_0I.t
    219 #01 foo0 bar0 foo1 bar1
    220 #02 bar0 foo1 bar1 foo1
    221 #03 foo0 bar0 foo1 bar1
    222 #04
    223 #07 bar0 foo1 bar1 foo0
    224 </tt></pre></li>
    225 <li>
    226 <p>This suppresses unique lines, comparing each line of the input file data starting from the third character:</p>
    227 <pre>
    228 <tt>uniq -d -s 2 uniq_0I.t
    229 </tt></pre>
    230 <p>In the last example, the <i>uniq</i> utility found no input matching the above criteria.</p>
    231 </li>
    232 </ol>
    233 </blockquote>
    234 <h4 class="mansect"><a name="tag_20_138_18" id="tag_20_138_18"></a>RATIONALE</h4>
    235 <blockquote>
    236 <p>Some historical implementations have limited lines to be 1080 bytes in length, which does not meet the implied {LINE_MAX}
    237 limit.</p>
    238 <p>Earlier versions of this standard allowed the <b>-</b><i>number</i> and <b>+</b><i>number</i> options. These options are no
    239 longer specified by POSIX.1-2024 but may be present in some implementations.</p>
    240 </blockquote>
    241 <h4 class="mansect"><a name="tag_20_138_19" id="tag_20_138_19"></a>FUTURE DIRECTIONS</h4>
    242 <blockquote>
    243 <p>If this utility is directed to create a new directory entry that contains any bytes that have the encoded value of a
    244 &lt;newline&gt; character, implementations are encouraged to treat this as an error. A future version of this standard may require
    245 implementations to treat this as an error.</p>
    246 </blockquote>
    247 <h4 class="mansect"><a name="tag_20_138_20" id="tag_20_138_20"></a>SEE ALSO</h4>
    248 <blockquote>
    249 <p><a href="../utilities/comm.html#"><i>comm</i></a> , <a href="../utilities/sort.html#"><i>sort</i></a></p>
    250 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    251 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    252 </blockquote>
    253 <h4 class="mansect"><a name="tag_20_138_21" id="tag_20_138_21"></a>CHANGE HISTORY</h4>
    254 <blockquote>
    255 <p>First released in Issue 2.</p>
    256 </blockquote>
    257 <h4 class="mansect"><a name="tag_20_138_22" id="tag_20_138_22"></a>Issue 6</h4>
    258 <blockquote>
    259 <p>The obsolescent SYNOPSIS and associated text are removed.</p>
    260 <p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
    261 <p>IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;1-2002, item XCU/TC1/D6/40 is applied, adding <i>LC_COLLATE</i> to the ENVIRONMENT
    262 VARIABLES section, and changing &quot;the application shall ensure that&quot; in the OUTPUT FILES section.</p>
    263 </blockquote>
    264 <h4 class="mansect"><a name="tag_20_138_23" id="tag_20_138_23"></a>Issue 7</h4>
    265 <blockquote>
    266 <p>Austin Group Interpretation 1003.1-2001 #027 is applied, clarifying that <tt>'+'</tt> may be recognized as an option delimiter
    267 in the OPTIONS section.</p>
    268 <p>Austin Group Interpretation 1003.1-2001 #092 is applied.</p>
    269 <p>Austin Group Interpretation 1003.1-2001 #133 is applied, clarifying the behavior of the trailing &lt;newline&gt;.</p>
    270 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    271 <p>SD5-XCU-ERN-141 is applied, updating the EXAMPLES section.</p>
    272 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0199 [963] and XCU/TC2-2008/0200 [663] are applied.</p>
    273 </blockquote>
    274 <h4 class="mansect"><a name="tag_20_138_24" id="tag_20_138_24"></a>Issue 8</h4>
    275 <blockquote>
    276 <p>Austin Group Defect 251 is applied, encouraging implementations to disallow the creation of filenames containing any bytes that
    277 have the encoded value of a &lt;newline&gt; character.</p>
    278 <p>Austin Group Defect 1070 is applied, changing the APPLICATION USAGE section.</p>
    279 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    280 <p>Austin Group Defect 1492 is applied, changing the EXIT STATUS section.</p>
    281 </blockquote>
    282 <div class="box"><em>End of informative text.</em></div>
    283 <hr>
    284 <p>&nbsp;</p>
    285 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    286 <hr size="2" noshade>
    287 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    288 POSIX™ is a Trademark of The IEEE.<br>
    289 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    290 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    291 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    292 ]</font></center>
    293 <hr size="2" noshade>
    294 <div class="NAVHEADER">
    295 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    296 <tr class="nav">
    297 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/unget.html" accesskey="P">&lt;&lt;&lt;
    298 Previous</a></td>
    299 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    300 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/unlink.html" accesskey="N">Next
    301 &gt;&gt;&gt;</a></td>
    302 </tr>
    303 </table>
    304 <hr align="left" width="100%"></div>
    305 </body>
    306 </html>