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

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

Extract fields from /etc/passwd
head -3 /etc/passwd | cut -d: -f1,3,7
# Output:
# root:0:/usr/bin/bash
# bin:1:/usr/bin/nologin
# daemon:2:/usr/bin/nologin
# -d: = colon delimiter
# -f1,3,7 = fields 1, 3, and 7
Single field
cut -d: -f1 /etc/passwd | head -5
# Just usernames
Field range
cut -d: -f1-3 /etc/passwd | head -3
# Fields 1 through 3
Character range — fixed-width data
ls -l | cut -c1-10
# First 10 characters of each line (permissions field)
When to use cut vs awk
# cut: single delimiter, grab columns, done
cut -d, -f2 data.csv

# awk: need logic, multiple delimiters, transforms
awk -F, '$3 > 100 {print $2}' data.csv
# Rule: if you need an if-statement, use awk. If not, cut is simpler.

See Also

  • awk — when you need logic beyond field selection

  • tr — character-level transforms (cut works on fields, tr on characters)