cut out selected fields of each line of a file
cut -b list [-n] [file ... ]
cut -c list [file ... ]
cut -f list [-d char] [-s] [file ... ]
Use cut to cut
fields from each line of a file; in data base parlance, it implements
the projection of a relation.
The fields as specified by
list can be fixed length,
(-c or -b options) or the length can vary from line to line
and be marked with a field delimiter character like
tab (-f option).
cut can be used as a filter;
if no files are given, the standard input is used.
A file name of - explicitly refers to standard input.
cut processes supplementary code set characters,
and recognizes supplementary code set characters in the char
given to the -d option (see below)
according to the locale specified in the LC_CTYPE
(see LANG on
The list argument is
a comma or blank separated
list of positive integer field numbers or ranges. In either case
the field numbers start at 1.
Ranges can take one of the three forms below, where number is an
Represents all the fields from the first number to the second
Represents all the fields from number to the last field, inclusive.
Represents all the fields from the first to number, inclusive.
The elements in the list can be repeated, can overlap, and can be
specified in any order. It is not an error to select fields that are not
present in an input line. See the ``Usage'' section for examples.
The meanings of the options are:
The fields specified in list represent bytes. The selected bytes are
written to the output, unless -n option is also specified.
Do not split characters. When the -b option is specified with
this option, each element in list of the form
low-high is modified as follows:
If the byte selected by low is not the first byte of a character,
low is decremented to select the first byte of the character
originally selected by low.
If the byte selected by high is not the last byte of a character,
high is decremented to select the last byte of the character prior
to the character originally selected by high, or zero if there is
no prior character.
If the resulting range element has high equal to zero or low
greater than high, the list element is dropped from list for
that input line without causing an error.
Each element of list in the form low-
is treated as described for low-high above, with high set
to the number of bytes in the current line, excluding the terminating
Each element of list in the form -high
is treated like low-high above, with low set to 1.
Each element of list that is given as a single number, num, is
treated like low-high above with low and high
set to num.
The fields specified in list represent characters. (This differs
from -b because a single character may be many bytes.)
The fields specified in list represent fields
assumed to be separated in the file by a delimiter character (see
Lines with no field delimiters will be passed through intact (useful
for table subheadings), unless
Output fields are separated by a single occurrence of the delimiter character.
The field delimiter used by -f is char.
The default is
Space or other characters with special meaning to the shell must be quoted.
char may be a
supplementary code set character.
Suppresses lines with no delimiter characters when used with the
UX:cut:ERROR:line too long
A line can have no more than 1023 bytes or fields,
or there is no new-line character.
UX:cut:ERROR:bad list for b/c/f option
Missing -b, -c or -f
option or incorrectly specified list.
No error occurs if a line has fewer fields than the
list calls for.
The list is empty.
The char argument to the -d option is too long, usually because more than one character was specified.
UX:cut:ERROR:Option requires an argument -- option
You must specify an argument for the given option.
UX:cut:ERROR:cannot handle multiple adjacent backspaces
Adjacent backspaces cannot be processed correctly.
UX:cut:WARNING:cannot open <filename
cannot be read or does not exist.
If multiple filenames are present, processing continues.
Any of the following strings are legal lists:
1,4,7 (copies fields 1, 4 and 7 only);
1-3 8 (copies fields 1, 2, 3, and 8 only);
-5,10 (short for 1-5,10); or
3- (short for third through last field). Note that
blank separated lists need to be surrounded by quotes on the
The following are some useful examples:
cut -d: -f1,5 /etc/passwd
mapping of user login IDs to names
cut -d : -f "1 3" /etc/passwd
mapping of user login IDs to user numeric IDs
name=`who am i | cut -f1 -d" "`
to set name to current login name.
language-specific message file
(see LANG on
to make horizontal cuts (by context) through a file, or
to put files together column-wise (that is, horizontally).
To reorder columns in a table, use cut and paste.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004