O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

cut — stdin  stdout  - file  -- opt  --help  --version

Synopsis

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

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

$ cut -c19 myfile

or 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 -f5 -d, 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 the -f option. 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required