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 ] [ -wF | -W ]
[ file ... ]
Use cut to cut out columns from a table or fields from
each line of one or more files. The fields as specified by
list can be fixed length, that is, character positions as
on a punched card (-c option), or the length can vary
from line to line and be marked with a field delimiter character
like Tab (-f option). If no files are
specified, cut reads from the standard input.
cut can be used as a filter.
The list is a comma-separated list of integers (in
increasing order). It can be tab or blank-separated if it is
enclosed in quotes. A dash (-) can be used to indicate ranges, for
cut understands the following options:
fields 1, 3, and 7
fields 2, 3, 4, and 8
equivalent to 1-4,10
equivalent to the second through last field
list specifies byte positions. For example, -b
1-100 cuts the first 100 bytes of each line. Each selected byte
will be output unless explicitly suppressed by the -n
list specifies character positions. For example, -c
1-72 would keep the first 72 characters of each line.
list specifies fields assumed to be separated in the file
by a delimiter character (see -d). For example, -f
1,7 copies the first and seventh field only. Lines with no
field delimiters will be passed through intact (useful for table
subheadings), unless -s is specified.
The character following -d is the field delimiter
(-f option only). Default is Tab. Space or other
characters with special meaning to the shell must be quoted.
Do not split characters. Used in conjunction with the -b
option as in the following example:
cut -b 1-100 -n file
Here 1 is the low byte and 100 is the high
byte. If the low byte is not the first byte of a character, its
value will be decremented by 1 so that the first byte of a character
is selected. Similarly, if the specified high byte is not the last
byte of a character, its value will be decremented by 1 so that the
selected byte becomes the last byte of the character prior to the
character selected on the command line.
If the -f option is used, -s suppresses lines
with no delimiter characters. Unless specified, lines with no
delimiters will be passed through untouched.
If the -f option is used, -w treats any
whitespace as a delimiter.
If the -f option is used, -F folds adjacent
Convenience abbreviation for -wF.
One of the options -b, -c or -f must
cut returns a value of 0 if it executes successfully. A
failure to open an input file results in a return status of 1; all
other fatal errors result in a return status of 2.
The following error messages may be displayed:
bad list for c / f option
Missing -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.
Map user IDs to names:
cut -d: -f 1,3 /etc/passwd
Set name to current login name:
name=`who am i | cut -f1 -d" "`
to make horizontal ``cuts'' (by context) through a file, or
to put files together horizontally.
To reorder columns in a table, use cut and
cut is conformant with:
ISO/IEC DIS 99452:1992, Information technology Portable Operating System Interface (POSIX) Part 2: Shell and Utilities (IEEE Std 1003.21992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003