Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

cut

v(uutils coreutils) 0.13.0
cut OPTION... [FILE]...

Extract sections from each line of files.

Options

--bytes=<LIST>, -b <LIST>

extract bytes listed in LIST

--characters=<LIST>, -c <LIST>

extract characters listed in LIST

--delimiter=<DELIM>, -d <DELIM>

use DELIM as field separator (default: Tab)

--whitespace-delimited=<trimmed>, -w <trimmed>

use any whitespace (Space/Tab) as delimiter; ignore leading and trailing blanks with ‘trimmed’

--fields=<LIST>, -f <LIST>

extract fields listed in LIST

-F <LIST>

like -f, but merge adjacent delimiters; the delimiter defaults to whitespace and the output delimiter to a space

--complement

invert selection: print all columns except the specified ones

--only-delimited, -s

suppress lines that do not contain the delimiter

--zero-terminated, -z

use NULL (\0) instead of newline as line terminator

--output-delimiter=<NEW_DELIM>, -O <NEW_DELIM>

replace input delimiter with NEW_DELIM in output

--no-partial, -n

with -b, do not output partial multi-byte characters

If no FILE is specified, reads from stdin. Use ‘-’ as a FILE argument to include stdin.

LIST is a comma-separated list of numbers or ranges:

N only column N N- columns N through the end of the line N-M columns N through M -M columns 1 through M

Examples:

cut -f 2,5-7 file.txt extract fields 2, 5, 6, and 7 cut -f 3- file.txt extract field 3 to the end of the line cut –complement -f 4-6 file.txt extract all fields except 4, 5, and 6 cut -d’,’ -f1 file.csv extract first field from a CSV

Examples

Print the fifth character on each line:

{{command}} | cut {{[-c|--characters]}} 5

Print the fifth to tenth character of each line of the specified file:

cut {{[-c|--characters]}} 5-10 {{path/to/file}}

Split each line in a file by a delimiter into fields and print fields two and six (default delimiter is TAB):

cut {{[-f|--fields]}} 2,6 {{path/to/file}}

Split each line by the specified delimiter and print all from the second field onward:

{{command}} | cut {{[-d|--delimiter]}} "{{delimiter}}" {{[-f|--fields]}} 2-

Use space as a delimiter and print only the first 3 fields:

{{command}} | cut {{[-d|--delimiter]}} " " {{[-f|--fields]}} -3

Only print lines that contain the delimiter:

{{command}} | cut {{[-d|--delimiter]}} "{{:}}" {{[-f|--fields]}} {{1}} {{[-s|--only-delimited]}}

Print specific fields of lines that use NUL to terminate lines instead of newlines:

{{find . -print0}} | cut {{[-z|--zero-terminated]}} {{[-d|--delimiter]}} "{{/}}" {{[-f|--fields]}} {{2}}

The examples are provided by the tldr-pages project under the CC BY 4.0 License.

Please note that, as uutils is a work in progress, some examples might fail.