tr—translates characters

tr [ –cds ] [ string1 [ string2 ] ]

tr copies the standard input to the standard output with substitution or deletion of selected characters. Input characters found in string1 are mapped into the corresponding characters of string2. The forward slash can be used with an octal digit to represent the ASCII code. When string2 (with any repetitions of characters) contains fewer characters than string1, characters in string1 with no corresponding character in string2 are not translated. Octal values for characters may be used when preceded with a backslash:

\11   Tab
\12   New line
\042  Single quote
\047  Double quote
Example A.65.
1  tr 'A' 'B' < filex
2  tr '[A-Z]' '[a-z]' < filex
3  tr -d ' ' < filex
4  tr -s '\11' '\11' ...

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.