Home·Terminal commands

cut

Text processing

Usage

cut -d, -f2 [file]

Slices out fixed fields or character positions; the delimiter is a single character and repeated delimiters are not merged, so whitespace-aligned columns are awk's job.

Common flags

FlagMeaning
-dThe delimiter, exactly one character
-fWhich fields to keep, as in -f1,3 or -f2-
-cKeep character positions instead of fields
-bKeep byte positions
-sDrop lines that contain no delimiter at all
-wBSD and macOS: use runs of whitespace as the delimiter
--complementGNU: keep everything except the selection

Examples

cut -d: -f1 /etc/passwd

Every user name.

cut -c1-8 access.log

The first eight characters of each line.

cut -d, -f2- data.csv

Everything from the second column on.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does cut do?

Slices out fixed fields or character positions; the delimiter is a single character and repeated delimiters are not merged, so whitespace-aligned columns are awk's job.

Q. How do I type it?

cut -d, -f2 [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man cut. This command sits under Text processing.

Related commands

man page: man cut