Glossary

tr

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.

Related terms: sed, awk, cut

Discussed in:

This site is currently in Beta. Contact: Chris Paton

Textbook of AI · Textbook of Usability · Textbook of Digital Health

Auckland Maths and Science Tutoring

AI tools used: Claude (research, coding, text), ChatGPT (diagrams, images), Grammarly (editing).