Learn cut — 25 Examples with Outputs

Compact, copy-paste-ready HTML file with commands and sample outputs. Use it as a quick reference or print it to PDF.

25 examples
Example 1 — Extract first field (default delimiter: TAB)Fields: TAB, -f1
cat <<'EOF' > data.txt
alice	bob	charlie
dave	erin	frank
EOF

cut -f1 data.txt
Output:
alice
dave
Example 2 — Extract multiple fields (1 and 3) with comma delimiter-d',' -f1,3
cat <<'EOF' > csv.txt
alice,bob,charlie
dave,erin,frank
EOF

cut -d',' -f1,3 csv.txt
Output:
alice,charlie
dave,frank
Example 3 — Extract a range of fields (2–4)-d':' -f2-4
cat <<'EOF' > example.txt
one:two:three:four:five
a:b:c:d:e
EOF

cut -d':' -f2-4 example.txt
Output:
two:three:four
b:c:d
Example 4 — Extract from a field to end (-f3-)Delimiter: |
cat <<'EOF' > fruits.txt
apple|banana|cherry|date
x|y|z
EOF

cut -d'|' -f3- fruits.txt
Output:
cherry|date
z
Example 5 — Extract up to a field (-f-2)Delimiter: -
cat <<'EOF' > letters.txt
1-2-3-4
a-b-c-d-e
EOF

cut -d'-' -f-2 letters.txt
Output:
1-2
a-b
Example 6 — Using --complement to remove fields (remove field 2)Delimiter: :
cat <<'EOF' > people.txt
first:middle:last
john:fitzgerald:kennedy
jane:anna:doe
EOF

cut -d':' --complement -f2 people.txt
Output:
first:last
john:kennedy
jane:doe
Example 7 — Suppress lines with no delimiter (-s)Use when some lines lack the delimiter
cat <<'EOF' > mixed.txt
foo,bar,baz
no_delim_line
a,b,c
EOF

cut -d',' -f2 -s mixed.txt
Output:
bar
b
Example 8 — Extract character positions (-c1-5)Characters 1–5
cat <<'EOF' > words.txt
elephant
cat
lioness
EOF

cut -c1-5 words.txt
Output:
eleph
cat
lione
Example 9 — Extract single byte positions (-b1-3)Be careful with UTF-8 multibyte chars
cat <<'EOF' > bytes.txt
abcdef
123456
EOF

cut -b1-3 bytes.txt
Output:
abc
123
Example 10 — Extract the last field using rev + cutA simple trick
cat <<'EOF' > path.txt
/home/user/docs/report.txt
/var/log/syslog
EOF

rev path.txt | cut -d'/' -f1 | rev
Output:
report.txt
syslog
Example 11 — Change output delimiter (GNU --output-delimiter)Replace delimiter between selected fields
cat <<'EOF' > data2.txt
a,b,c
d,e,f
EOF

cut -d',' -f1,3 --output-delimiter='|' data2.txt
Output:
a|c
d|f
Example 12 — Cut from a pipeline: PIDs from psBe aware output varies by system
ps aux | head -n 3 | tr -s ' ' | cut -d' ' -f2
Output (illustrative):
1
234
5678
Example 13 — Extract filename extensionsUse rev trick to get last dot-separated part
cat <<'EOF' > files.txt
archive.tar.gz
photo.jpg
README
EOF

rev files.txt | cut -d'.' -f1 | rev
Output:
gz
jpg
README
Example 14 — Tab-separated column (default)Get column 2
cat <<'EOF' > tabs.txt
col1	col2	col3
1	2	3
x	y	z
EOF

cut -f2 tabs.txt
Output:
col2
2
y
Example 15 — Extract usernames from /etc/passwdField 1 is username
head -n 5 /etc/passwd | cut -d':' -f1
Output (example):
root
daemon
bin
sys
sync
Example 16 — Extract unique first fields then sortCombine with sort -u
cat <<'EOF' > colors.csv
red,blue,green
blue,yellow,red
green,red,blue
EOF

cut -d',' -f1 colors.csv | sort -u
Output:
green
red
Example 17 — Multiple character ranges-c1-3,7-9
cat <<'EOF' > text.txt
ABCDEFGHIJ
0123456789
EOF

cut -c1-3,7-9 text.txt
Output:
ABCGHI
012678
Example 18 — Fixed-width columns (bytes)Use -b for byte ranges
cat <<'EOF' > report.txt
ID  Name       Score
01  Alice      093
02  Bob        087
EOF

cut -b1-3,5-14,16-18 report.txt
Output:
ID  Name       Score
01  Alice      093
02  Bob        087
Example 19 — Remove leading field (remove field 1)--complement -f1
cat <<'EOF' > sample.txt
A:1:foo:bar
B:2:baz:qux
EOF

cut -d':' --complement -f1 sample.txt
Output:
1:foo:bar
2:baz:qux
Example 20 — Extract header field from CSVShow column name for field 2
cat <<'EOF' > dataset.csv
id,name,email
1,Alice,a@example.com
2,Bob,b@example.com
EOF

head -n1 dataset.csv | cut -d',' -f2
Output:
name
Example 21 — Use paste then cutCombine two files side-by-side
cat <<'EOF' > a.txt
apple
banana
cherry
EOF

cat <<'EOF' > b.txt
red
yellow
red
EOF

paste a.txt b.txt | cut -f1
Output:
apple
banana
cherry
Example 22 — Space-separated columns (squeeze spaces first)Use tr -s ' ' then cut
cat <<'EOF' > spaced.txt
col1   col2    col3
one    two     three
EOF

tr -s ' ' < spaced.txt | cut -d' ' -f3
Output:
col3
three
Example 23 — Fields that contain commas (use alternate delimiter)Delimiter: |
cat <<'EOF' > weird.txt
"Smith, John"|30|"New York, NY"
"Doe, Jane"|25|"San Francisco, CA"
EOF

cut -d'|' -f1,3 weird.txt
Output:
"Smith, John"|"New York, NY"
"Doe, Jane"|"San Francisco, CA"
Example 24 — seq + paste to create columnsGroup sequence into columns and cut column 2
seq 1 6 | paste - - - | cut -f2
Output:
2
5
Example 25 — Combine grep + cutFilter lines then extract fields
cat <<'EOF' > services.txt
ssh:22:open
http:80:open
smtp:25:closed
ftp:21:open
EOF

grep ':open$' services.txt | cut -d':' -f1,2
Output:
ssh:22
http:80
ftp:21