cut(C)
cut --
cut out selected fields of each line of a file
Syntax
cut -b list [ -n ]
[ file ... ]
cut -c list [ file ... ]
cut -f list [ -d
char ] [ -s ] [ -wF | -W ]
[ file ... ]
Description
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
example:
 1,3,7
- 
fields 1, 3, and 7
 2-4,8
- 
fields 2, 3, 4, and 8
 -4,10
- 
equivalent to 1-4,10
 2-
- 
equivalent to the second through last field
cut understands the following options:
 -b list
- 
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
option).
 -c list
- 
list specifies character positions. For example, -c
1-72 would keep the first 72 characters of each line.
 -f list
- 
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.
 -d char
- 
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.
 
 -n
- 
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.
 
 -s
- 
If the -f option is used, -s suppresses lines
with no delimiter characters. Unless specified, lines with no
delimiters will be passed through untouched.
 -w
- 
If the -f option is used, -w treats any
whitespace as a delimiter.
 -F
- 
If the -f option is used, -F folds adjacent
delimiters together.
 -s
- 
Convenience abbreviation for -wF.
One of the options -b, -c or -f must
be specified.
Exit values
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.
Diagnostics
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.
 - no fields
- 
The list is empty.
Examples
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" "`
Limitations
Use
grep(C)
to make horizontal ``cuts'' (by context) through a file, or
paste(C)
to put files together horizontally.
To reorder columns in a table, use cut and
paste.
See also
grep(C),
paste(C)
Standards conformance
cut is conformant with:
ISO/IEC DIS 9945 2:1992, Information technology
2:1992, Information technology  Portable Operating System Interface (POSIX)
 Portable Operating System Interface (POSIX)  Part 2: Shell and Utilities (IEEE Std 1003.2
 Part 2: Shell and Utilities (IEEE Std 1003.2 1992);
1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.
© 2005 The SCO Group, Inc.  All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005