tr — stdin stdout - file -- opt --help --version
tr command performs
some simple, useful translations of one set of characters into
another. For example, to capitalize everything in a file:
$ cat myfile This is a very wonderful file. $ cat myfile | tr 'a-z' 'A-Z' THIS IS A VERY WONDERFUL FILE.
or to change all vowels into asterisks:
$ cat myfile | tr aeiouAEIOU '*' Th*s *s * v*ry w*nd*rf*l f*l*.
or to delete all vowels:
$ cat myfile | tr -d aeiouAEIOU Ths s vry wndrfl fl.
As a very practical example, delete all carriage returns from
a DOS text file so it’s more compatible with Linux text utilities
$ tr -d '\r' < dosfile > newfile
tr translates the first
charset1 into the first
charset2, the second into
the second, the third into the third, etc. If the length of
only the first
N characters in
charset2 are used. (If
charset1 is longer than
charset2, see the
Character sets can have the following forms.
The sequence of characters A, B, C, D.
The range of characters from A to B.
y repetitions of the character x.
The same character
tr also understands the
escape characters “\a” (
^G = ring
bell), “\b” (
^H = backspace),
^L = formfeed), “\n”
^J = newline), “\r” (
^M = return), “\t” (
^I = tab), and “\v” (
^K = vertical tab) accepted by
printf (see Screen Output), as well ...