cut(1)


cut -- cut out selected fields of each line of a file

Synopsis

cut -b list [-n] [file ... ]

cut -c list [file ... ]

cut -f list [-d char] [-s] [file ... ]

Description

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 environment variable (see LANG on environ(5)).

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 unsigned integer.


number-number
Represents all the fields from the first number to the second number.

number-
Represents all the fields from number to the last field, inclusive.

-number
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:


-b list
The fields specified in list represent bytes. The selected bytes are written to the output, unless -n option is also specified.

-n
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:

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 newline character.

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.


-c list
The fields specified in list represent characters. (This differs from -b because a single character may be many bytes.)

-f list
The fields specified in list represent fields assumed to be separated in the file by a delimiter character (see -d). Lines with no field delimiters will be passed through intact (useful for table subheadings), unless -s is specified. Output fields are separated by a single occurrence of the delimiter character.

-d char
The field delimiter used by -f is char. The default is tab. Space or other characters with special meaning to the shell must be quoted. char may be a supplementary code set character.

-s
Suppresses lines with no delimiter characters when used with the -f option.

Errors


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.

UX:cut:ERROR:no fields
The list is empty.

UX:cut:ERROR:no delimiter
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>
Either filename cannot be read or does not exist. If multiple filenames are present, processing continues.

Usage

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 command line.

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.

Files


/usr/lib/locale/locale/LC_MESSAGES/uxcore
language-specific message file (see LANG on environ(5)).

References

grep(1), paste(1)

Notices

Use grep(1) to make horizontal cuts (by context) through a file, or paste(1) 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