<code>cut</code> is a shell command that extracts sections from each line of input text â usually from a file. Extraction of line segments can typically be done by bytes (<code>-b</code>), characters (<code>-c</code>), or fields (<code>-f</code>) separated by a delimiter (<code>-d</code> — the tab character by default). A range must be provided in each case which consists of one of <code>N</code>, <code>N-M</code>, <code>N-</code> (<code>N</code> to the end of the line), or <code>-M</code> (beginning of the line to <code>M</code>), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
The original Bell Labs version was written by Gottfried W. R. Luderer. The command is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. It first appeared in AT&T System III UNIX in 1982.
The command is commonly available on Unix and Unix-like operating systems. It is part of the BSD Base System. The version in GNU coreutils was written by David M. Ihnat, David MacKenzie, and Jim Meyering. The command is available for Windows via UnxUtils. The command was ported to the IBM i operating system.
The command line consists of options and an optional file path. If no path is specified than standard input will be used.
Options include:
Given a file named <code>foo</code> with content:
foo:bar:baz:qux:quux one:two:three:four:five:six:seven alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu the quick brown fox jumps over the lazy dog
To output the fourth through tenth characters of each line:
To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
Because the colon is not found in the last line, the entire line is shown.
Option <code>-d</code> specifies a single character delimiter (in the example above it is a colon) which serves as field separator. Option <code>-f</code> which specifies range of fields included in the output (here fields range from five till the end). Option <code>-d</code> presupposes usage of option <code>-f</code>.
To output the third field of each line using space as the field delimiter:
Because the space character is not found in the first three lines these entire lines are shown.
To separate two words having any delimiter: