Some text jobs are too small for awk and too fiddly for an editor: take the second column, lowercase everything, join two files side by side. That is the exact territory of cut, tr, and paste — three small tools that each do one obvious thing.
cut: columns out #
$ cut -d: -f1,7 /etc/passwd
$ cut -c1-10 long-lines.txt
-d sets the delimiter, -f picks fields, and -c slices by characters when there is no delimiter at all. The passwd example prints users and their shells — a classic quick audit.
tr: characters across #
tr translates or deletes single characters, always reading stdin:
$ echo "Version 2.0.1" | tr 'A-Z' 'a-z'
$ echo "call 555-1234" | tr -d '0-9'
$ echo "too many spaces" | tr -s ' '
That last one, squeeze, is the tidy-up pass for messy command output. Uppercase a whole file in a pipe:
$ head -1 notes.txt | tr 'a-z' 'A-Z'
paste: streams together #
paste joins lines side by side — the inverse of cut, and the fastest way to build a two-column table from two lists:
$ paste names.txt scores.txt
$ paste -d, names.txt scores.txt > pairs.csv
| Tool | One job |
|---|---|
cut | Extract fields or character ranges |
tr | Translate, squeeze, or delete characters |
paste | Merge lines across files |
rev | Reverse each line (honourable mention) |
A small assembly line #
Chained, the three replace a spreadsheet import:
$ paste -d, <(cut -f1 data.tsv) <(cut -f3 data.tsv) | tr -s ' ' > clean.csv
Process substitution — the <(...) form — feeds each cut as a file; it is shell trickery worth an evening of practice on its own.
Counting what you cut? sort and uniq finish that job. The full terminal notes series covers each hand-off like this one.
