tr performs character-level substitutions, deletions, and squeezes on stdin. It is small and old but invaluable in pipelines.
tr 'a-z' 'A-Z' < file # lowercase → uppercase
tr -d '\r' < windows.txt # strip carriage returns
tr -s ' ' # squeeze repeated spaces to one
tr -c 'A-Za-z0-9\n' ' ' < text # replace everything except letters/digits
echo 'hello world' | tr ' ' '\n' # one word per line
Unlike sed, tr works character by character, not by regex, which makes it fast and predictable for simple transformations.
Discussed in:
- Chapter 8: Text Processing — Simple Transformations