Linux and Unix tr command

Quick links

About tr
Syntax
Examples
Related commands
Linux and Unix main page

About tr

Translate characters.

Syntax

tr [-c] [-d] [-s] [string1] [string2]

-cComplement the set of characters specified by string1.
-dDelete all occurrences of input characters that are specified by string1.
-sReplace instances of repeated characters with a single character.
string1First string or character to be changed.
string2Second string or character to change the string1.

Examples

echo "12345678 9247" | tr 123456789 computerh

This example takes an echo response of '12345678 9247' and pipes it through the tr replacing the appropriate numbers with the letters. In this example it would return computer hope.

tr -cd '\11\12\40-\176' < myfile1 > myfile2

This example would take the file myfile1 and strip all non printable characters and take that results to myfile2.

Related commands

ed
sed
sh