>

tr

transliterate: replaces chars in one list with corresponding chars in another list (all of one char replaced by another, or with nothing, i.e. delete all of a char). Limited form of editing: global find and replace. File can get smaller but never bigger.
Pure filter (standard input only).
/usr/ucb/tr BSD tr has this easier syntax.

Ex. myfile Newline at end. tr sees newlines, i.e. is not "line-oriented" like grep and sed.
Computo, ergo sum.

$ tr a-z A-Z <myfile # capitalize all letters
COMPUTO, ERGO SUM.

$ tr aeiou X <myfile # change lowercase vowels to X
CXmpXtX, XrgX sXm.

-d option: one list of chars to delete
$ tr -d aeiou <myfile # delete lowercase vowels
Cmpt, rg sm.

$ tr -d \\r <dosfile
# delete the carriage return \r chars of a DOS file. od -c to see

-c option: use opposite of first list
$ tr -c aeiou '*' <myfile # change every char except lowercase vowel to *
*o**u*o**e**o**u***$
(newline changed too)

-s option: compress (squeeze) runs of same converted char into one char
$ tr -cs aeiou '*' <myfile
*o*u*o*e*o*u*$

tr -dc a-zA-Z <myfile #delete non-letters

Ex. Convert input to one word per line:
$ tr -cs A-Za-z '\n' <myfile # non-letters convert to newline, compress. Octal 12=newline
Computo
ergo
sum
$
tr -s ' '  ' '     #squeeze runs of spaces to single space

tr '()' '{}'       # change parens to braces

tr ab ba           # swap a and b

tr \'\" \"\'       # swap single and double quotes

tr -cs 0-9 ''      #all digits only, onto one line