cut: Extract Columns
cut extracts parts of each line: selected fields (columns separated by a delimiter), characters at fixed positions, or bytes. It's simpler and faster than awk when the data has one clean delimiter, such as CSV, TSV or /etc/passwd.
Fields with -d and -f
-d sets the delimiter (one character, default tab) and -f chooses the fields:
cat > employees.csv <<'CSV'
id,name,department,city
101,Ada,Engineering,London
102,Linus,Engineering,Helsinki
103,Grace,Research,New York
CSV
cut -d, -f2 employees.csv
echo "---"
cut -d, -f2,4 employees.csv
echo "---"
cut -d, -f1-3 employees.csv | tail -n 1name
Ada
Linus
Grace
---
name,city
Ada,London
Linus,Helsinki
Grace,New York
---
103,Grace,Research
| Field list | Meaning |
|---|---|
-f2 |
Field 2 |
-f1,3 |
Fields 1 and 3 |
-f2-4 |
Fields 2 to 4 |
-f3- |
Field 3 to the end |
-f-2 |
Fields 1 and 2 |
--complement -f2 |
Everything except field 2 (GNU) |
Note that cut keeps fields in their original order: -f4,2 prints field 2 before field 4. To reorder columns use awk.
Real system files
/etc/passwd lists user accounts with :-separated fields: name:password:UID:GID:comment:home:shell.
cut -d: -f1,7 /etc/passwd | tail -n 3
echo "---"
grep '^learner:' /etc/passwd | cut -d: -f6guest:/sbin/nologin
nobody:/sbin/nologin
learner:/bin/bash
---
/home/learner
Characters with -c
-c selects character positions, useful for fixed-width data such as log timestamps or IDs:
cat > events.log <<'LOG'
2026-03-01T08:15:00 login ada
2026-03-01T09:40:12 upload linus
2026-03-02T11:05:59 logout ada
LOG
cut -c1-10 events.log
echo "---"
cut -c12-16 events.log
echo "---"
cut -c21- events.log2026-03-01
2026-03-01
2026-03-02
---
08:15
09:40
11:05
---
login ada
upload linus
logout ada
Output delimiter and complement
printf 'sku;name;price;stock\nA1;pen;1.20;300\nB7;notebook;3.50;120\n' > stock.txt
cut -d';' -f2,3 --output-delimiter=' => ' stock.txt
echo "---"
cut -d';' --complement -f4 stock.txt
echo "---"
cut -d';' -s -f2 stock.txt
echo "no separator here" | cut -d';' -s -f1
echo "(-s printed nothing for the line without ';')"name => price
pen => 1.20
notebook => 3.50
---
sku;name;price
A1;pen;1.20
B7;notebook;3.50
---
name
pen
notebook
(-s printed nothing for the line without ';')
The ; delimiter must be quoted because ; is special to the shell. -s (only delimited) skips lines that don't contain the delimiter at all; without it, such lines are printed whole.
The space-separated trap
cut treats every delimiter character as a separator, so two spaces in a row create an empty field. Command output aligned with several spaces breaks it; awk or tr -s ' ' (squeeze) fixes that:
printf 'nginx running 2\npostgres running 12\n' > services.txt
cut -d' ' -f2 services.txt
echo "--- cut sees empty fields; squeeze the spaces first:"
tr -s ' ' < services.txt | cut -d' ' -f2
echo "--- or let awk split on runs of whitespace:"
awk '{ print $2 }' services.txt
running
--- cut sees empty fields; squeeze the spaces first:
running
running
--- or let awk split on runs of whitespace:
running
running
cut in pipelines
cat > access.log <<'LOG'
10.0.0.5 - - "GET /api/users HTTP/1.1" 200
10.0.0.9 - - "GET /api/orders HTTP/1.1" 500
10.0.0.5 - - "POST /api/login HTTP/1.1" 200
LOG
cut -d' ' -f1 access.log | sort -u
cut -d'"' -f2 access.log | cut -d' ' -f210.0.0.5
10.0.0.9
/api/users
/api/orders
/api/login
Splitting on " first and then on spaces pulls the URL out of the quoted request: chaining two simple cuts is often easier than writing one complicated pattern.
Note:
cutdoesn't understand CSV quoting: a field like"Smith, John"contains a comma and will be split. For real-world CSV, use a CSV-aware tool (csvkit,mlr, Python'scsvmodule).
Test yourself
Which command prints the first field of a colon-separated file?
- cut -c1 file
- cut -d: -f1 file
- cut -f: -d1 file
- cut -d1 -f: file
What does cut -c1-4 print for the line 2026-03-01?
- 2026-
- 2026
- 03-01
- -03-
Why does cut -d' ' -f2 fail on columns aligned with several spaces?
- cut can't use spaces
- Each space is a separator, so consecutive spaces create empty fields
- cut needs -s
- Spaces must be written as \s