|Skip Navigation Links|
|Exit Print View|
|man pages section 1: User Commands Oracle Solaris 10 8/11 Information Library|
- cut out selected fields of each line of a file
cut -b list [-n] [file]...
cut -c list [file]...
cut -f list [-d delim] [-s] [file]...
Use the cut utility to cut out columns from a table or 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, 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). cut can be used as a filter.
Either the -b, -c, or -f option must be specified.
The following options are supported:
A comma-separated or blank-character-separated list of integer field numbers (in increasing order), with optional - to indicate ranges (for instance, 1,4,7; 1-3,8; -5,10 (short for 1-5,10); or 3- (short for third through last field)).
The list following -b specifies byte positions (for instance, -b1-72 would pass the first 72 bytes of each line). When -b and -n are used together, list is adjusted so that no multi-byte character is split.
The list following -c specifies character positions (for instance, -c1-72 would pass the first 72 characters of each line).
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. delim can be a multi-byte character.
The list following -f is a list of fields assumed to be separated in the file by a delimiter character (see -d ); for instance, -f1,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.
Do not split characters. When -b list and -n are used together, list is adjusted so that no multi-byte character is split.
Suppresses lines with no delimiter characters in case of -f option. Unless specified, lines with no delimiters will be passed through untouched.
The following operands are supported:
A path name of an input file. If no file operands are specified, or if a file operand is -, the standard input will be used.
See largefile(5) for the description of the behavior of cut when encountering files greater than or equal to 2 Gbyte (231 bytes).
Example 1 Mapping user IDs
A mapping of user IDs to names follows:
example% cut -d: -f1,5 /etc/passwd
Example 2 Setting current login name
To set name to current login name:
example$ name=`who am i | cut -f1 -d' '`
See environ(5) for descriptions of the following environment variables that affect the execution of cut: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
The following exit values are returned:
All input files were output successfully.
An error occurred.
See attributes(5) for descriptions of the following attributes:
Either file cannot be read or does not exist. If multiple files are present, processing continues.
Missing delim on -d option.
Missing list on -b, -c, or -f option.