Name

cut -(b|c|f)range [options] [files] — coreutils

Synopsis

/usr/bin stdin stdout - file -- opt --help --version

The cut command extracts columns of text from files. A “column” is defined either by character offsets (e.g., the nineteenth character of each line):

$ cut -c19 myfile

by byte offsets (which are often the same as characters, unless you have multibyte characters in your language):

$ cut -b19 myfile

or by delimited fields (e.g., the fifth field in each line of a comma-delimited file):

$ cut -d, -f5 myfile

You aren’t limited to printing a single column: you can provide a range (3–16), a comma-separated sequence (3,4,5,6,8,16), or both (3,4,8-16). For ranges, if you omit the first number (–16), a 1 is assumed (1–16); if you omit the last number (5–), the end of line is used.

Useful options

-d C

Use character C as the input delimiter character between fields for -f. By default it’s a tab character.

--output-delimiter=C

Use character C as the output delimiter character between fields for -f. By default it’s a tab character.

-s

Suppress (don’t print) lines that don’t contain the delimiter character.

Get Linux Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.