Previous Section  < Day Day Up >  Next Section

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

Newline

\042

Single quote

\047

Double quote


Example A.63.

1   tr 'A' 'B' < filex

2   tr '[A-Z]' [a-z]' < filex

3   tr -d ' ' < filex

4   tr -s '\11' '\11' < filex

5   tr -s ':' ' ' < filex

6   tr '\047' '\042'


EXPLANATION

  1. Translates As to Bs in filex.

  2. Translates all uppercase letters to lowercase letters.

  3. Deletes all spaces from filex.

  4. Replaces (squeezes) multiple tabs with single tabs in filex.

  5. Squeezes multiple colons into single spaces in filex.

  6. Translates double quotes to single quotes in text coming from standard input.

    Previous Section  < Day Day Up >  Next Section