cut — Field Selection

The simplest field extractor — when you need one or two columns from delimited data, cut is faster to type than awk.

Field Extraction — -f and -d

Extract first field with default tab delimiter
cut -f1 data.tsv
Extract username from /etc/passwd — colon delimiter
cut -d':' -f1 /etc/passwd
Extract multiple fields — username, UID, shell
cut -d':' -f1,3,7 /etc/passwd
Extract a range of fields — fields 2 through 5
cut -d',' -f2-5 report.csv
Extract from field 3 to end of line
cut -d':' -f3- /etc/passwd
Extract fields 1 through 3 — everything up to the third field
cut -d',' -f-3 report.csv

Character Extraction — -c

Extract characters 1-10 — fixed-width formatted data
cut -c1-10 fixed_width.txt
Extract the first character of every line — quick category column
cut -c1 data.txt
Extract specific character positions — useful for columnar reports
cut -c1-8,20-35,50-60 mainframe_report.txt

Byte Extraction — -b

Extract bytes 1-4 — relevant for binary-adjacent or multibyte awareness
cut -b1-4 data.bin
Difference between -c and -b matters with UTF-8 multibyte characters
printf 'cafe\xcc\x81\n' | cut -c1-4
printf 'cafe\xcc\x81\n' | cut -b1-4

Complement — --complement

Print everything EXCEPT field 2 — inverse selection
cut -d',' -f2 --complement report.csv
Remove the password field from /etc/passwd (field 2)
cut -d':' -f2 --complement /etc/passwd
Drop characters 1-5 — keep everything from position 6 onward
cut -c1-5 --complement padded.txt

Multi-Field Selection Patterns

Non-contiguous fields — skip the middle
cut -d':' -f1,3,6,7 /etc/passwd
Combine ranges and individual fields
cut -d',' -f1,3-5,8 data.csv

Delimiter Gotchas

Space delimiter requires quoting — common mistake
cut -d' ' -f2 space_separated.txt
cut treats each character as a potential delimiter — double spaces cause empty fields
# This fails on multi-space-separated output like ps or df
ps aux | cut -d' ' -f2    # Empty fields from consecutive spaces
# Use awk instead — it handles runs of whitespace
ps aux | awk '{print $2}'
Tab delimiter is the default — explicit when needed
cut -f2 data.tsv                     # Default: tab delimiter
cut -d$'\t' -f2 data.tsv             # Explicit tab (same result)
Pipe delimiter — must quote to avoid shell interpretation
cut -d'|' -f1,3 pipe_delimited.txt

cut vs awk — When to Reach for Each

cut is faster for simple single-delimiter extraction — no regex engine
# cut: fast, simple, one delimiter character only
cut -d':' -f1 /etc/passwd

# awk: handles regex delimiters, multiple consecutive delimiters, reordering
awk -F':' '{print $1}' /etc/passwd
cut cannot reorder fields — awk can
# cut always outputs in original order regardless of -f order
cut -d':' -f7,1 /etc/passwd    # Still outputs field 1 then 7

# awk lets you reorder
awk -F':' '{print $7, $1}' /etc/passwd
cut cannot handle multi-character delimiters — awk can
# Fails: cut only accepts single character
# cut -d'::' -f2 data.txt

# Works: awk handles multi-char FS
awk -F'::' '{print $2}' data.txt

Practical Pipelines

Extract PATH directories — one per line
echo "$PATH" | tr ':' '\n' | cut -d'/' -f1-3 | sort -u
Quick CSV column inspection — number the headers
head -1 report.csv | tr ',' '\n' | awk '{printf "%2d  %s\n", NR, $0}'
# Then extract the columns you need:
cut -d',' -f3,7,12 report.csv
Extract hostnames from SSH config
awk '/^Host / {print $2}' ~/.ssh/config | cut -d'.' -f1