Bash Cut Columns

cut slices delimited or fixed-width text into columns, making it the quickest tool for pulling specific fields out of a file without writing a script.

What Is cut?

cut extracts pieces of each line of input based on a delimiter and field numbers, or on fixed character positions. It does not compute anything and cannot reorder columns, but for simply pulling one or two fields out of delimited text it is faster to type and run than awk. The examples below use the same team.csv file of employee records.

Example

$ cat team.csv
name,department,age,salary
Alice Johnson,Engineering,29,85000
Bob Smith,Marketing,34,62000
carol white,engineering,41,95000
David Lee,Sales,26,54000
Eve Davis,Marketing,38,71000
Frank Miller,Engineering,45,110000
grace hopper,Sales,31,67000
$ cut -d',' -f1 team.csv
name
Alice Johnson
Bob Smith
carol white
David Lee
Eve Davis
Frank Miller
grace hopper

Selecting Multiple Fields with -f

The -d flag sets the delimiter and -f chooses which fields to keep. -f accepts a comma-separated list like -f1,4, or a range like -f1-3, and cut always prints the selected fields joined by the original delimiter, in the order they appear in the source file.

Example

$ cut -d',' -f1,4 team.csv
name,salary
Alice Johnson,85000
Bob Smith,62000
carol white,95000
David Lee,54000
Eve Davis,71000
Frank Miller,110000
grace hopper,67000

Changing the Output Delimiter and Cutting by Character

--output-delimiter lets you print the selected fields with a different separator than the one you searched for, which is handy for turning a CSV into a more readable report. For text that has no consistent delimiter at all, -c selects fixed character positions instead of fields.

Example

$ cut -d',' -f1,3 --output-delimiter=' | ' team.csv
name | age
Alice Johnson | 29
Bob Smith | 34
carol white | 41
David Lee | 26
Eve Davis | 38
Frank Miller | 45
grace hopper | 31
  • Use ranges like -f1-3 to grab a contiguous block of fields instead of listing every one by hand.
  • -c selects character positions instead of delimited fields, e.g. cut -c1-10, which suits fixed-width text with no real delimiter.
  • --complement prints every field except the ones you list, so cut -d',' -f2 --complement team.csv drops just the department column.
  • cut always prints fields in the file's original order, even when you list them out of order in -f.
  • Pipe cut's output into sort, awk, or wc -l to build quick one-line reports from a single column.
FlagMeaning
-dSets the field delimiter, e.g. -d','
-fSelects one or more fields by number or range, e.g. -f1,4 or -f1-3
-cSelects character positions instead of delimited fields
--output-delimiterChanges the separator printed between selected fields
--complementInverts the selection, printing every field except the ones given
Note: cut treats every delimiter literally, so a real CSV field that contains a quoted comma, such as a last name written as Smith, Bob, will be split in the wrong place; for quoted or irregular CSVs reach for awk or a dedicated CSV tool instead.