Viewing and processing text

Command cut

Cut fields or character ranges

Linux · Bash examples · commands run on the selected server

When to use cut

Use cut to extract fixed character positions or explicitly separated fields. It is a good fit for simple records; whitespace-aligned tables and quoted CSV usually require a more capable parser.

Syntax

cut [OPTIONS] [FILE...]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-d SYMBOL
Field separator; default is tab.
-f LIST
Select fields by number.
-c LIST
Select character positions according to the implementation.

Usage examples

Show logins

cut -d: -f1 /etc/passwd

The first colon-delimited field lists account names.

Select two fields

cut -d: -f1,3 /etc/passwd

The first and third fields produce account names and numeric user IDs.

Select character positions from each line

cut -c1-20 ./report.txt

The beginning of each line is extracted; character and byte handling can depend on the implementation and locale.

Notes and limitations

  • The -d delimiter consists of one character; consecutive spaces are not collapsed.
  • For complex CSV and Unicode processing, check the utility's limitations and use a suitable parser.

Common questions and troubleshooting

Why do repeated spaces create unexpected fields?

A literal delimiter separates every occurrence; it does not collapse variable whitespace. Use awk when whitespace-separated columns are intended.

Can cut select columns from complex CSV?

Not reliably when delimiters occur inside quoted fields. Use a parser that understands CSV quoting and record boundaries.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man cut.