isposix

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

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

cut.html (18102B)


      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>cut</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/ctags.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/cxref.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="cut" id="cut"></a> <a name="tag_20_28" id="tag_20_28"></a><!-- cut -->
     29 <h4 class="mansect"><a name="tag_20_28_01" id="tag_20_28_01"></a>NAME</h4>
     30 <blockquote>cut — cut out selected fields of each line of a file</blockquote>
     31 <h4 class="mansect"><a name="tag_20_28_02" id="tag_20_28_02"></a>SYNOPSIS</h4>
     32 <blockquote class="synopsis">
     33 <p><code><tt>cut -b</tt> <i>list</i> <b>[</b><tt>-n</tt><b>] [</b><i>file</i><tt>...</tt><b>]</b> <tt><br>
     34 <br>
     35 cut -c</tt> <i>list</i> <b>[</b><i>file</i><tt>...</tt><b>]</b> <tt><br>
     36 <br>
     37 cut -f</tt> <i>list</i> <b>[</b><tt>-d</tt> <i>delim</i><b>] [</b><tt>-s</tt><b>] [</b><i>file</i><tt>...</tt><b>]</b> <tt><br>
     38 </tt></code></p>
     39 </blockquote>
     40 <h4 class="mansect"><a name="tag_20_28_03" id="tag_20_28_03"></a>DESCRIPTION</h4>
     41 <blockquote>
     42 <p>The <i>cut</i> utility shall cut out bytes (<b>-b</b> option), characters (<b>-c</b> option), or character-delimited fields
     43 (<b>-f</b> option) from each line in one or more files, concatenate them, and write them to standard output.</p>
     44 </blockquote>
     45 <h4 class="mansect"><a name="tag_20_28_04" id="tag_20_28_04"></a>OPTIONS</h4>
     46 <blockquote>
     47 <p>The <i>cut</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     48 Guidelines</i></a> .</p>
     49 <p>The application shall ensure that the option-argument <i>list</i> (see options <b>-b</b>, <b>-c</b>, and <b>-f</b> below) is a
     50 &lt;comma&gt;-separated list or &lt;blank&gt;-separated list of positive numbers and ranges. Ranges can be in three forms. The
     51 first is two positive numbers separated by a &lt;hyphen-minus&gt; (<i>low</i>-<i>high</i>), which represents all fields from the
     52 first number to the second number. The second is a positive number preceded by a &lt;hyphen-minus&gt; (-<i>high</i>), which
     53 represents all fields from field number 1 to that number. The third is a positive number followed by a &lt;hyphen-minus&gt;
     54 (<i>low</i>-), which represents that number to the last field, inclusive. The elements in <i>list</i> can be repeated, can overlap,
     55 and can be specified in any order, but the bytes, characters, or fields selected shall be written in the order of the input data.
     56 If an element appears in the selection list more than once, it shall be written exactly once.</p>
     57 <p>The following options shall be supported:</p>
     58 <dl compact>
     59 <dd></dd>
     60 <dt><b>-b&nbsp;</b><i>list</i></dt>
     61 <dd>Cut based on a <i>list</i> of bytes. Each selected byte shall be output unless the <b>-n</b> option is also specified. It shall
     62 not be an error to select bytes not present in the input line.</dd>
     63 <dt><b>-c&nbsp;</b><i>list</i></dt>
     64 <dd>Cut based on a <i>list</i> of characters. Each selected character shall be output. It shall not be an error to select
     65 characters not present in the input line.</dd>
     66 <dt><b>-d&nbsp;</b><i>delim</i></dt>
     67 <dd>Set the field delimiter to the character <i>delim</i>. The default is the &lt;tab&gt;.</dd>
     68 <dt><b>-f&nbsp;</b><i>list</i></dt>
     69 <dd>Cut based on a <i>list</i> of fields, assumed to be separated in the file by a delimiter character (see <b>-d</b>). Each
     70 selected field shall be output. Output fields shall be separated by a single occurrence of the field delimiter character. Lines
     71 with no field delimiters shall be passed through intact, unless <b>-s</b> is specified. It shall not be an error to select fields
     72 not present in the input line.</dd>
     73 <dt><b>-n</b></dt>
     74 <dd>Do not split characters. When specified with the <b>-b</b> option, each element in <i>list</i> of the form
     75 <i>low</i>-<i>high</i> (&lt;hyphen-minus&gt;-separated numbers) shall be modified as follows:
     76 <ul>
     77 <li>
     78 <p>If the byte selected by <i>low</i> is not the first byte of a character, <i>low</i> shall be decremented to select the first
     79 byte of the character originally selected by <i>low</i>. If the byte selected by <i>high</i> is not the last byte of a character,
     80 <i>high</i> shall be decremented to select the last byte of the character prior to the character originally selected by
     81 <i>high</i>, or zero if there is no prior character. If the resulting range element has <i>high</i> equal to zero or <i>low</i>
     82 greater than <i>high</i>, the list element shall be dropped from <i>list</i> for that input line without causing an error.</p>
     83 </li>
     84 </ul>
     85 <p>Each element in <i>list</i> of the form <i>low</i>- shall be treated as above with <i>high</i> set to the number of bytes in the
     86 current line, not including the terminating &lt;newline&gt;. Each element in <i>list</i> of the form -<i>high</i> shall be treated
     87 as above with <i>low</i> set to 1. Each element in <i>list</i> of the form <i>num</i> (a single number) shall be treated as above
     88 with <i>low</i> set to <i>num</i> and <i>high</i> set to <i>num</i>.</p>
     89 </dd>
     90 <dt><b>-s</b></dt>
     91 <dd>Suppress lines with no delimiter characters, when used with the <b>-f</b> option. Unless specified, lines with no delimiters
     92 shall be passed through untouched.</dd>
     93 </dl>
     94 </blockquote>
     95 <h4 class="mansect"><a name="tag_20_28_05" id="tag_20_28_05"></a>OPERANDS</h4>
     96 <blockquote>
     97 <p>The following operand shall be supported:</p>
     98 <dl compact>
     99 <dd></dd>
    100 <dt><i>file</i></dt>
    101 <dd>A pathname of an input file. If no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt>, the
    102 standard input shall be used.</dd>
    103 </dl>
    104 </blockquote>
    105 <h4 class="mansect"><a name="tag_20_28_06" id="tag_20_28_06"></a>STDIN</h4>
    106 <blockquote>
    107 <p>The standard input shall be used only if no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt>. See
    108 the INPUT FILES section.</p>
    109 </blockquote>
    110 <h4 class="mansect"><a name="tag_20_28_07" id="tag_20_28_07"></a>INPUT FILES</h4>
    111 <blockquote>
    112 <p>The input files shall be text files, except that line lengths shall be unlimited.</p>
    113 </blockquote>
    114 <h4 class="mansect"><a name="tag_20_28_08" id="tag_20_28_08"></a>ENVIRONMENT VARIABLES</h4>
    115 <blockquote>
    116 <p>The following environment variables shall affect the execution of <i>cut</i>:</p>
    117 <dl compact>
    118 <dd></dd>
    119 <dt><i>LANG</i></dt>
    120 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    121 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    122 variables used to determine the values of locale categories.)</dd>
    123 <dt><i>LC_ALL</i></dt>
    124 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    125 <dt><i>LC_CTYPE</i></dt>
    126 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    127 opposed to multi-byte characters in arguments and input files).</dd>
    128 <dt><i>LC_MESSAGES</i></dt>
    129 <dd><br>
    130 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
    131 <dt><i>NLSPATH</i></dt>
    132 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    133 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    134 "0"></dd>
    135 </dl>
    136 </blockquote>
    137 <h4 class="mansect"><a name="tag_20_28_09" id="tag_20_28_09"></a>ASYNCHRONOUS EVENTS</h4>
    138 <blockquote>
    139 <p>Default.</p>
    140 </blockquote>
    141 <h4 class="mansect"><a name="tag_20_28_10" id="tag_20_28_10"></a>STDOUT</h4>
    142 <blockquote>
    143 <p>The <i>cut</i> utility output shall be a concatenation of the selected bytes, characters, or fields (one of the following):</p>
    144 <pre>
    145 <tt>"%s\n", &lt;</tt><i>concatenation of bytes</i><tt>&gt;
    146 <br>
    147 "%s\n", &lt;</tt><i>concatenation of characters</i><tt>&gt;
    148 <br>
    149 "%s\n", &lt;</tt><i>concatenation of fields and field delimiters</i><tt>&gt;
    150 </tt></pre></blockquote>
    151 <h4 class="mansect"><a name="tag_20_28_11" id="tag_20_28_11"></a>STDERR</h4>
    152 <blockquote>
    153 <p>The standard error shall be used only for diagnostic messages.</p>
    154 </blockquote>
    155 <h4 class="mansect"><a name="tag_20_28_12" id="tag_20_28_12"></a>OUTPUT FILES</h4>
    156 <blockquote>
    157 <p>None.</p>
    158 </blockquote>
    159 <h4 class="mansect"><a name="tag_20_28_13" id="tag_20_28_13"></a>EXTENDED DESCRIPTION</h4>
    160 <blockquote>
    161 <p>None.</p>
    162 </blockquote>
    163 <h4 class="mansect"><a name="tag_20_28_14" id="tag_20_28_14"></a>EXIT STATUS</h4>
    164 <blockquote>
    165 <p>The following exit values shall be returned:</p>
    166 <dl compact>
    167 <dd></dd>
    168 <dt>&nbsp;0</dt>
    169 <dd>All input files were output successfully.</dd>
    170 <dt>&gt;0</dt>
    171 <dd>An error occurred.</dd>
    172 </dl>
    173 </blockquote>
    174 <h4 class="mansect"><a name="tag_20_28_15" id="tag_20_28_15"></a>CONSEQUENCES OF ERRORS</h4>
    175 <blockquote>
    176 <p>Default.</p>
    177 </blockquote>
    178 <hr>
    179 <div class="box"><em>The following sections are informative.</em></div>
    180 <h4 class="mansect"><a name="tag_20_28_16" id="tag_20_28_16"></a>APPLICATION USAGE</h4>
    181 <blockquote>
    182 <p>The <i>cut</i> and <a href="../utilities/fold.html"><i>fold</i></a> utilities can be used to create text files out of files with
    183 arbitrary line lengths. The <i>cut</i> utility should be used when the number of lines (or records) needs to remain constant. The
    184 <a href="../utilities/fold.html"><i>fold</i></a> utility should be used when the contents of long lines need to be kept
    185 contiguous.</p>
    186 <p>Earlier versions of the <i>cut</i> utility worked in an environment where bytes and characters were considered equivalent
    187 (modulo &lt;backspace&gt; and &lt;tab&gt; processing in some implementations). In the extended world of multi-byte characters, the
    188 new <b>-b</b> option has been added. The <b>-n</b> option (used with <b>-b</b>) allows it to be used to act on bytes rounded to
    189 character boundaries. The algorithm specified for <b>-n</b> guarantees that:</p>
    190 <pre>
    191 <tt>cut -b 1-500 -n file &gt; file1
    192 cut -b 501- -n file &gt; file2
    193 </tt></pre>
    194 <p>ends up with all the characters in <b>file</b> appearing exactly once in <b>file1</b> or <b>file2</b>. (There is, however, a
    195 &lt;newline&gt; in both <b>file1</b> and <b>file2</b> for each &lt;newline&gt; in <b>file</b>.)</p>
    196 </blockquote>
    197 <h4 class="mansect"><a name="tag_20_28_17" id="tag_20_28_17"></a>EXAMPLES</h4>
    198 <blockquote>
    199 <p>Examples of the option qualifier list:</p>
    200 <dl compact>
    201 <dd></dd>
    202 <dt>1,4,7</dt>
    203 <dd>Select the first, fourth, and seventh bytes, characters, or fields and field delimiters.</dd>
    204 <dt>1-3,8</dt>
    205 <dd>Equivalent to 1,2,3,8.</dd>
    206 <dt>-5,10</dt>
    207 <dd>Equivalent to 1,2,3,4,5,10.</dd>
    208 <dt>3-</dt>
    209 <dd>Equivalent to third to last, inclusive.</dd>
    210 </dl>
    211 <p>The <i>low</i>-<i>high</i> forms are not always equivalent when used with <b>-b</b> and <b>-n</b> and multi-byte characters; see
    212 the description of <b>-n</b>.</p>
    213 <p>The following command:</p>
    214 <pre>
    215 <tt>cut -d : -f 1,6 /etc/passwd
    216 </tt></pre>
    217 <p>reads the System V password file (user database) and produces lines of the form:</p>
    218 <pre>
    219 <tt>&lt;</tt><i>user ID</i><tt>&gt;:&lt;</tt><i>home directory</i><tt>&gt;
    220 </tt></pre>
    221 <p>Most utilities in this volume of POSIX.1-2024 work on text files. The <i>cut</i> utility can be used to turn files with
    222 arbitrary line lengths into a set of text files containing the same data. The <a href="../utilities/paste.html"><i>paste</i></a>
    223 utility can be used to create (or recreate) files with arbitrary line lengths. For example, if <b>file</b> contains long lines:</p>
    224 <pre>
    225 <tt>cut -b 1-500 -n file &gt; file1
    226 cut -b 501- -n file &gt; file2
    227 </tt></pre>
    228 <p>creates <b>file1</b> (a text file) with lines no longer than 500 bytes (plus the &lt;newline&gt;) and <b>file2</b> that contains
    229 the remainder of the data from <b>file</b>. (Note that <b>file2</b> is not a text file if there are lines in <b>file</b> that are
    230 longer than 500 + {LINE_MAX} bytes.) The original file can be recreated from <b>file1</b> and <b>file2</b> using the command:</p>
    231 <pre>
    232 <tt>paste -d "\0" file1 file2 &gt; file
    233 </tt></pre></blockquote>
    234 <h4 class="mansect"><a name="tag_20_28_18" id="tag_20_28_18"></a>RATIONALE</h4>
    235 <blockquote>
    236 <p>Some historical implementations do not count &lt;backspace&gt; characters in determining character counts with the <b>-c</b>
    237 option. This may be useful for using <i>cut</i> for processing <i>nroff</i> output. It was deliberately decided not to have the
    238 <b>-c</b> option treat either &lt;backspace&gt; or &lt;tab&gt; characters in any special fashion. The <a href=
    239 "../utilities/fold.html"><i>fold</i></a> utility does treat these characters specially.</p>
    240 <p>Unlike other utilities, some historical implementations of <i>cut</i> exit after not finding an input file, rather than
    241 continuing to process the remaining <i>file</i> operands. This behavior is prohibited by this volume of POSIX.1-2024, where only
    242 the exit status is affected by this problem.</p>
    243 <p>The behavior of <i>cut</i> when provided with either mutually-exclusive options or options that do not work logically together
    244 has been deliberately left unspecified in favor of global wording in <a href="../utilities/V3_chap01.html#tag_18_04"><i>1.4 Utility
    245 Description Defaults</i></a> .</p>
    246 <p>The OPTIONS section was changed in response to IEEE PASC Interpretation 1003.2 #149. The change represents historical practice
    247 on all known systems. The original standard was ambiguous on the nature of the output.</p>
    248 <p>The <i>list</i> option-arguments are historically used to select the portions of the line to be written, but do not affect the
    249 order of the data. For example:</p>
    250 <pre>
    251 <tt>echo abcdefghi | cut -c6,2,4-7,1
    252 </tt></pre>
    253 <p>yields <tt>"abdefg"</tt>.</p>
    254 <p>A proposal to enhance <i>cut</i> with the following option:</p>
    255 <dl compact>
    256 <dd></dd>
    257 <dt><b>-o</b></dt>
    258 <dd>Preserve the selected field order. When this option is specified, each byte, character, or field (or ranges of such) shall be
    259 written in the order specified by the <i>list</i> option-argument, even if this requires multiple outputs of the same bytes,
    260 characters, or fields.</dd>
    261 </dl>
    262 <p>was rejected because this type of enhancement is outside the scope of the IEEE&nbsp;P1003.2b draft standard.</p>
    263 </blockquote>
    264 <h4 class="mansect"><a name="tag_20_28_19" id="tag_20_28_19"></a>FUTURE DIRECTIONS</h4>
    265 <blockquote>
    266 <p>None.</p>
    267 </blockquote>
    268 <h4 class="mansect"><a name="tag_20_28_20" id="tag_20_28_20"></a>SEE ALSO</h4>
    269 <blockquote>
    270 <p><a href="../utilities/V3_chap02.html#tag_19_05"><i>2.5 Parameters and Variables</i></a> , <a href=
    271 "../utilities/fold.html#"><i>fold</i></a> , <a href="../utilities/grep.html#"><i>grep</i></a> , <a href=
    272 "../utilities/paste.html#"><i>paste</i></a></p>
    273 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    274 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    275 </blockquote>
    276 <h4 class="mansect"><a name="tag_20_28_21" id="tag_20_28_21"></a>CHANGE HISTORY</h4>
    277 <blockquote>
    278 <p>First released in Issue 2.</p>
    279 </blockquote>
    280 <h4 class="mansect"><a name="tag_20_28_22" id="tag_20_28_22"></a>Issue 6</h4>
    281 <blockquote>
    282 <p>The OPTIONS section is changed to align with the IEEE&nbsp;P1003.2b draft standard.</p>
    283 <p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
    284 </blockquote>
    285 <h4 class="mansect"><a name="tag_20_28_23" id="tag_20_28_23"></a>Issue 7</h4>
    286 <blockquote>
    287 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    288 <p>SD5-XCU-ERN-171 is applied, adding APPLICATION USAGE.</p>
    289 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0080 [584] is applied.</p>
    290 </blockquote>
    291 <h4 class="mansect"><a name="tag_20_28_24" id="tag_20_28_24"></a>Issue 8</h4>
    292 <blockquote>
    293 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    294 </blockquote>
    295 <div class="box"><em>End of informative text.</em></div>
    296 <hr>
    297 <p>&nbsp;</p>
    298 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    299 <hr size="2" noshade>
    300 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    301 POSIX™ is a Trademark of The IEEE.<br>
    302 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    303 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    304 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    305 ]</font></center>
    306 <hr size="2" noshade>
    307 <div class="NAVHEADER">
    308 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    309 <tr class="nav">
    310 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/ctags.html" accesskey="P">&lt;&lt;&lt;
    311 Previous</a></td>
    312 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    313 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/cxref.html" accesskey="N">Next
    314 &gt;&gt;&gt;</a></td>
    315 </tr>
    316 </table>
    317 <hr align="left" width="100%"></div>
    318 </body>
    319 </html>