📄 cut.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>cut</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_301"> </a>NAME</h4><blockquote>cut - cut out selected fields of each line of a file</blockquote><h4><a name = "tag_001_014_302"> </a>SYNOPSIS</h4><blockquote><pre><code>cut -b <i>list </i><b>[</b>-n<b>] [</b><i>file</i> ...<b>]</b>cut -c <i>list </i><b>[</b><i>file</i> ...<b>]</b>cut -f <i>list </i><b>[</b>-d <i>delim</i><b>][</b>-s<b>][</b><i>file</i> ...<b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_303"> </a>DESCRIPTION</h4><blockquote>The<i>cut</i>utility will cut out bytes(<b>-b</b>option), characters(<b>-c</b>option) or character-delimited fields(<b>-f</b>option) from eachline in one or more files, concatenate them and write themto standard output.</blockquote><h4><a name = "tag_001_014_304"> </a>OPTIONS</h4><blockquote>The<i>cut</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> .<p>The option-argument<i>list</i>(see options<b>-b</b>,<b>-c</b>and<b>-f</b>below) must be a comma-separated list orblank-character-separatedlist of positive numbers and ranges.Ranges can be in three forms.The first is two positive numbers separated by a hyphen(<i>low-high</i>),which representsall fields from the first number to the second number.The second is a positive number preceded by a hyphen(<i>-high</i>),which represents all fields from field number 1 to that number.The third is a positive number followed by a hyphen(<i>low-</i>),which represents that number to the last field, inclusive.The elements in list can be repeated, can overlap and can bespecified in any order.<p>The following options are supported:<dl compact><dt><b>-b </b><i>list</i><dd>Cut based on a<i>list</i>of bytes.Each selected byte will be output unless the<b>-n</b>option is also specified.It is not an error to select bytes not present in the input line.<dt><b>-c </b><i>list</i><dd>Cut based on a<i>list</i>of characters.Each selected character is output.It is not an errorto select characters not present in the input line.<dt><b>-d </b><i>delim</i><dd>Set the field delimiter to the character<i>delim</i>.The default is thetabcharacter.<dt><b>-f </b><i>list</i><dd>Cut based on a<i>list</i>of fields, assumed to be separated in the file bya delimiter character (see<b>-d</b>).Each selected field will be output.Output fields will be separated bya single occurrence of the field delimiter character.Lines with no field delimiters will be passed through intact,unless<b>-s</b>is specified.It is not an error to select fields not present in the input line.<dt><b>-n</b><dd>Do not split characters.When specified with the<b>-b</b>option, each element in<i>list</i>of the form<i>low-high</i>(hyphen-separated numbers)will be modified as follows:<ul><li>If the byte selected by<i>low</i>is not the first byte of a character,<i>low</i>will be decremented to select the first byte of the character originallyselected by<i>low</i>.If the byte selected by<i>high</i>is not the last byte ofa character,<i>high</i>will be decremented to select the last byte of thecharacter prior to the character originally selected by<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>greater than<i>high</i>,the list element will be dropped from<i>list</i>for that input line without causing an error.</ul>Each element in<i>list</i>of the form<i>low-</i>will be treated as above with<i>high</i>set to the number of bytes in the current line, not including theterminating newline character.Each element in<i>list</i>of the form<i>-high</i>will be treated as above with<i>low</i>set to 1.Each element in<i>list</i>of the form<i>num</i>(a single number)will be treated as above with<i>low</i>set to<i>num</i>and<i>high</i>set to<i>num</i>.<dt><b>-s</b><dd>Suppress lines with no delimiter characters, when used with the<b>-f</b>option.Unless specified, lines with no delimiters will be passedthrough untouched.</dl></blockquote><h4><a name = "tag_001_014_305"> </a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>file</i><dd>A pathname of an input file.If no<i>file</i>operands are specified, or if a<i>file</i>operand is "-", the standard input will be used.</dl></blockquote><h4><a name = "tag_001_014_306"> </a>STDIN</h4><blockquote>The standard input will be used only if no<i>file</i>operands are specified, or if a<i>file</i>operand is "-".See the INPUT FILES section.</blockquote><h4><a name = "tag_001_014_307"> </a>INPUT FILES</h4><blockquote>The input files must be text files,except that line lengths are unlimited.</blockquote><h4><a name = "tag_001_014_308"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>cut</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i></dl></blockquote><h4><a name = "tag_001_014_309"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_310"> </a>STDOUT</h4><blockquote>The<i>cut</i>utility output will be a concatenation of the selectedbytes, characters or fields (one of the following):<p><code><tt>"%s\n"</tt>, <<i>concatenation of bytes</i>><p><tt>"%s\n"</tt>, <<i>concatenation of characters</i>><p><tt>"%s\n"</tt>, <<i>concatenation of fields and field delimiters</i>></code></blockquote><h4><a name = "tag_001_014_311"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_001_014_312"> </a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_313"> </a>EXTENDED DESCRIPTION</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_314"> </a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>All input files were output successfully.<dt>>0<dd>An error occurred.</dl></blockquote><h4><a name = "tag_001_014_315"> </a>CONSEQUENCES OF ERRORS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_316"> </a>APPLICATION USAGE</h4><blockquote>Earlier versions of the<i>cut</i>utility worked in an environment wherebytes and characters were considered equivalent (modulobackspaceandtab characterprocessing in some implementations).In the extended world of multi-byte characters, the new<b>-b</b>option has been added.The<b>-n</b>option (used with<b>-b</b>)allows it to be used toact on bytes rounded to character boundaries.The algorithm specified for<b>-n</b>guarantees that:<pre><code>cut -b 1-500 -n file > file1cut -b 501- -n file > file2</code></pre>will end up with all the characters in<b>file</b>appearing exactly once in<b>file1</b>or<b>file2</b>.(There is, however, anewlinecharacter in both<b>file1</b>and<b>file2</b>for eachnewlinecharacter in<b>file</b>.)</blockquote><h4><a name = "tag_001_014_317"> </a>EXAMPLES</h4><blockquote>Examples of the option qualifier list:<dl compact><dt><b>1,4,7</b><dd>Select the first, fourth and seventh bytes,characters, or fields and field delimiters.<dt><b>1-3,8</b><dd>Equivalent to1,2,3,8.<dt><b>-5,10</b><dd>Equivalent to1,2,3,4,5,10.<dt><b>3-</b><dd>Equivalent to third to last, inclusive.</dl><p>The<i>low-high</i>forms are not always equivalent when used with<b>-b</b>and<b>-n</b>and multi-byte characters.See the description of<b>-n</b>.<p>The following command:<pre><code>cut -d : -f 1,6 /etc/passwd</code></pre><p>reads the System V password file (user database) andproduces lines of the form:<pre><code><user ID>:<home directory></code></pre><p>Most utilities in this specification work on text files.The<i>cut</i>utility can be used to turn files with arbitrary line lengthsinto a set of text files containing the same data.The<i><a href="paste.html">paste</a></i>utility can be used to create (or recreate) files with arbitraryline lengths.For example, if<b>file</b>contains long lines:<pre><code>cut -b 1-500 -n file > file1cut -b 501- -n file > file2</code></pre>creates<b>file1</b>(a text file) with lines no longer than 500 bytes(plus thenewlinecharacter and<b>file2</b>that contains the remainder of the data from<b>file</b>.(Note that<b>file2</b>will not be atext file if there are lines in<b>file</b>that are longer than 500 +{LINE_MAX}bytes.)The original file can be recreated from<b>file1</b>and<b>file2</b>using the command:<pre><code>paste -d "\0" file1 file2 > file</code></pre></blockquote><h4><a name = "tag_001_014_318"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_319"> </a>SEE ALSO</h4><blockquote><i><a href="grep.html">grep</a></i>,<i><a href="paste.html">paste</a></i>,<xref href=parms><a href="chap2.html#tag_001_005">Parameters and Variables</a></xref>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -