tr [ -c | -cds | -cs | -ds | -s ] [ -A ] String1 String2
tr { -cd | -cs | -d | -s } [ -A ] String1
The tr command deletes or substitutes characters from standard input and writes the result to standard output. The tr command performs three kinds of operations depending on the strings specified by the String1 and String2 variable and on the flags specified.
If String1 and String2 are both specified and the -d flag is not specified, the tr command replaces each character contained in String1 from the standard input with the character in the same position in String2.
If the -d flag is specified, the tr command deletes each character contained in String1 from standard input.
If the -s flag is specified, the tr command removes all but the first character in any sequence of a character string represented in String1 or String2. For each character represented in String1, the tr command removes all but the first occurrence of the character from standard output. For each character represented in String2, the tr command removes all but the first occurrence in a sequence of occurrences of that character in the standard output.
The strings contained in the String1 and String2 variables can be expressed using the following conventions:
If a character is specified more than once in String1, the character is translated into the character in String2 that corresponds to the last occurrence of the character in String1.
If the strings specified by String1 and String2 are not the same length, the tr command ignores the extra characters in the longer string.
-A | Performs all operations on a byte-by-byte basis using the ASCII collation order for ranges and character classes, instead of the collation order for the current locale. |
-c | Specifies that the value of String1 be replaced by the complement of the string specified by String1. The complement of String1 is all of the characters in the character set of the current locale, except the characters specified by String1. If the -A and -c flags are both specified, characters are complemented with respect to the set of all 8-bit character codes. If the -c and -s flags are both specified, the -s flag applies to characters in the complement of String1. |
-d | Deletes each character from standard input that is contained in the string specified by String1. |
-s | Removes all but the first in a sequence of a repeated characters. Character sequences specified by String1 are removed from standard input before translation, and character sequences specified by String2 are removed from standard output. |
String1 | Specifies a string of characters. |
String2 | Specifies a string of characters. |
This command returns the following exit values:
0 | All input was processed successfully. |
>0 | An error occurred. |
tr '{}' '()' < textfile > newfileThis translates each { (left brace) to ( (left parenthesis) and each } (right brace) to ) (right parenthesis). All other characters remain unchanged.
tr '{}' '\[]' < textfile > newfileThis translates each { (left brace) to [ (left bracket) and each } (right brace) to ] (right bracket). The left bracket must be entered with a \ (backslash) escape character.
tr 'a-z' 'A-Z' < textfile > newfile
tr -cs '[:lower:][:upper:]' '[\n*]' < textfile > newfileThis translates each sequence of characters other than lowercase letters and uppercase letters into a single newline character. The * (asterisk) causes the tr command to repeat the new line character enough times to make the second string as long as the first string.
tr -d '\0' < textfile > newfile
tr -s '\n' < textfile > newfileOR
tr -s '\012' < textfile > newfile
tr -c '[:print:][:cntrl:]' '[?*]' < textfile > newfileThis scans a file created in a different locale to find characters that are not printable characters in the current locale.
tr -s '[:space:]' '[#*]'
The ed command, trbsd command.
The ctype subroutines.
National Language Support Overview for Programming in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.