cut — slice columns
cut picks fields out of structured input. Three modes:
cut -f 2— second tab-separated field.cut -d ',' -f 1,3— first and third comma-separated.cut -c 1-10— first 10 characters of each line.cut -d ' ' -f 2-— from field 2 to end.
Useful on CSV, TSV, and any line-oriented log with a fixed delimiter. For complex parsing prefer awk (next track).
tr — translate or delete characters
tr reads stdin character by character and translates. Two main forms:
tr 'a-z' 'A-Z'— uppercase.tr -d ' '— delete spaces.tr -s ' '— squeeze runs of spaces into one.tr -c 'a-zA-Z0-9' '_'— replace anything not alphanumeric with_(complement).
Real-world combos
- Get unique IPs from a log:
cut -d ' ' -f 1 access.log | sort -u - Lowercase a file:
tr 'A-Z' 'a-z' < INPUT > output - Strip Windows line endings:
tr -d '\r' < in.txt > out.txt - Replace tabs with spaces:
tr '\t' ' '
Limits of cut
cut can't handle quoted CSV (commas inside quotes). For real CSV use csvkit, miller, or Python's csv module. cut is fine for simple delimited logs.
cut stops being enough when data contains the delimiter
cut -d, does not understand CSV quoting or embedded commas. It fits a simple delimiter contract; formal CSV and escaped formats need a parser.
tr is sensitive to byte and locale boundaries
Character sets and ranges can change with locale, and multibyte text may not behave as intended. Use tr for bounded ASCII normalization and a Unicode-aware runtime for case or word transformations.