cut

NAME

cut - select fields of each line of a file

SYNOPSIS

cut -b list [-n] [file...]
cut -c list [file ...]
cut -f list [-d string] [-s] [file ...]

DESCRIPTION

The cut(1) utility selects portions of each line (as specified by list) from each file and writes them to the standard output. If no file is specified, or if the file is specified as a hyphen (-), the standard input is used. The items specified by list can be indicated in terms of column position or fields delimited by a special character. Column numbering starts from 1.

List is a comma-separated or white space-separated set of increasing numbers, number ranges, or both. Each number range consists of a number, a hyphen (-), and a second number. The number range selects a set of fields or columns ranging from the column or field specified by the first number to the column or field specified by the second number. Numbers or number ranges may be preceded by a hyphen (-), which selects all fields or columns from 1 to the first number. Numbers or number ranges may also be followed by a hyphen (-), which selects all fields or columns from the last number to the end of the line. Numbers and number ranges may repeat, overlap, and occur in any order. It is not an error to select fields or columns not present in the input line.

OPTIONS

-b list
Cut based on a list of bytes. Each selected byte will be output unless the -n option is also specified. It is not an error to select bytes not present in the input line.
-c list
The list specifies character positions.
-d string
Use the first character of string as the field delimiter character instead of the tab character.
-f list
The list specifies fields, delimited in the input by a single tab character. Output fields are separated by a single tab character.
-n
Do not split characters. When specified with the -b option, each element in list of the form low-high (hyphen-separated numbers) will be modified as follows:

If the byte selected by low is not the first byte of a character, low will be 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 will be 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 will be dropped from list for that input line without causing an error.

Each element in list of the form low- will be treated as above with high set to the number of bytes in the current line, not including the terminating newline character. Each element in list of the form -high will be treated as above with low set to 1. Each element in list of the form num (a single number) will be treated as above with low set to num and high set to num.

-s
Suppresses lines with no field delimiter characters. Unless specified, lines with no delimiters are passed through unmodified.

If file is specified on the command line by -, standard input is used. If no file is specified, standard input is used.

DIAGNOSTICS

The cut(1) utility exits 0 on success, and 1 if an error occurred.

SEE ALSO

paste(1)