Skip to content

cut

9 commands

Extracts columns, fields or characters from each line of input.

  • text processing
  • columns

Install cut

sudo apt install coreutils

Fields5

cut -d'<sep>' -f<n> <file>

Prints field n using a delimiter — here, every user name.

Link
cut -d'<sep>' -f<a>,<b> <file>

Prints several fields; the delimiter is kept between them.

Link
cut -d'<sep>' -f<a>- <file>

Prints field n and everything after it.

Link
cut -d'<sep>' -f<n> --output-delimiter='<s>' <file>

Changes the delimiter used in the output (GNU).

Link
cut -d'<sep>' -s -f<n> <file>

Skips lines that do not contain the delimiter.

Link

Characters and bytes2

cut -c<a>-<b> <file>

Prints characters a through b of each line.

Link
cut -b<n> <file>

Selects bytes instead of characters.

Link

In pipelines2

<command> | cut -d' ' -f<n>

Extracts a column from command output — here, logged-in users.

Link
cut -d' ' -f1 <log> | sort | uniq -c | sort -rn

The classic top-talkers pipeline for web logs.

Link