COHERENT manpages
This page displays the COHERENT manpage for cut [Select portions of each line of its input].
List of available manpages
Index
cut -- Command
Select portions of each line of its input
cut -clist [file ...]
cut -flist [-s] [-d char] [file ...]
cut ``cuts'' one or pieces out of each line in its input, and writes the
piece or pieces to the standard output. list specifies the pieces to cut
out of each line. cut reads its input from file; if no file is named on
its command line, cut reads the standard input.
A ``piece'' of an input line can be defined either as one or more
characters from fixed positions in the line; or as one or more fields. The
option -c selects characters from fixed positions; you would use this
option if you were cutting up a file each of whose lines was of a fixed
length. The option -f selects fields. A field does not have to have a
fixed length, but its end must be marked by some special character; by
default, a white-space character marks the end of a field. Option -d lets
you specify the ``magic character'' that marks the end of a field. Option
-s tells cut to throw away every line that does not contain the field-
delimiter character. By default, cut will pass through unmodified every
line that does not contain the field delimiter.
Options -c and -f are each followed by a list, which describes the pieces
that you want from each input line. A piece is defined as follows:
N A piece consists of a single column or field. For example, the
command
cut -f2 /etc/ttytype
selects field 2 from file /etc/ttytype.
N-N The range of columns or fields. For example, command
cut -c4-12 /etc/ttytype
selects columns 4 through 12, inclusive, from file /etc/ttytype.
-N Select every column or field from the beginning of the line through N.
For example, command
cut -d\| -f-3
reads the first three fields from the standard input.
N- Select every column or field from N through the end of the line. For
example, the command
cut -c15-
selects every character from character 15 through the end of the line.
If list defines more than one piece, the definitions of the pieces must be
separated by commas. For example, the command
cut -c3-5,7-9
cuts columns three through five and seven through nine from the standard
input, and writes them onto the standard output.
cut returns zero on success, one if an error occurred.
Examples
The following cuts column 4 through the end of the line from file
/etc/ttys, and writes the cut piece onto the standard output. In effect,
it throws away the first three columns of every line in that file:
cut -c4- /etc/ttys
You would use this command to display every serial-port device name that
that file contains.
The next command selects fields one and six from file /etc/passwd. (Field
one in this file gives a user's login identifier; and field six gives her
home directory.) Note that fields in this file are delimited by a colon
`:'.
cut -d: -f1,6 /etc/passwd
The final example cuts the first field from the input. It also explicitly
sets the field delimiter to the space character. You would use this
command to clip any trailing white space from data read from the standard
input:
cut -f1 -d' '
See Also
awk,
commands,
paste,
sed
Notes
cut is copyright © 1988,1990 by The Regents of the University of
California. All rights reserved.