TR(1,C) AIX Commands Reference TR(1,C) ------------------------------------------------------------------------------- tr PURPOSE Translates characters. SYNTAX +--------+ +-----------+ +-----------+ /usg/tr ---| +----+ |---| |---| |---| +-| -A |-+ +- string1 -+ +- string2 -+ ^| -c || || -d || || -s || |+----+| +------+ +--------+ +-----------+ +-----------+ /usr/ucb/tr ---| +----+ |---| |---| |---| +-| -A |-+ +- string1 -+ +- string2 -+ ^| -c || || -d || || -s || |+----+| +------+ Note: This command does not have MBCS support. DESCRIPTION The tr command copies characters from the standard input to the standard output with substitution or deletion of selected characters. Input characters from string1 are replaced with the corresponding characters in string2. tr cannot handle an ASCII NUL (\000) in string1 or string2; it always deletes NUL from the input. Note: AIX is shipped with /usr/bin/tr linked to /usg/tr. Unless this link is modified, entering tr executes /usg/tr (that is, you do not have to use the full path name). In the AIX version abbreviations that can be used to introduce ranges of characters or repeated characters are: [a-z] Stands for a string of characters whose ASCII codes run from character a to character z, inclusive. Processed July 12, 1991 TR(1,C) 1 TR(1,C) AIX Commands Reference TR(1,C) [a*num] Stands for num repetitions of a. The value of num is considered to be in decimal unless the first digit of num is 0, in which case it is considered to be in octal. When num is 0 or is omitted, it is treated as a number large enough to pad string2 with a. In the BSD version, the abbreviation that can be used to introduce ranges of characters is: a-z Stands for a string of characters whose ASCII codes run from character a to character z inclusive. Brackets are not special characters and the hyphen (-) is a special character. Use the escape character \ (back slash) to remove special meaning from any character in a string. Use the \ followed by 1, 2, or 3 octal digits for the ASCII code of a character. FLAGS -A Translates on a byte-by-byte basis. When you specify this flag, tr does not support extended characters. -c Complements (inverts) the set of characters in string1 with respect to the universe of characters whose ASCII codes are 001 through 377 octal, if you specify -A, and all non-null characters, if you do not specify -A. -d Deletes all input characters in string1. -s Changes characters that are repeated output characters in string2 into single characters. EXAMPLES 1. To translate braces into parentheses: /usg/tr '{}' '()' newfile This translates each "{" to "(" and each "}" to ")". All other characters remain unchanged. 2. To translate lowercase characters to uppercase: /usg/tr '[a-z]' '[A-Z]' newfile or /usr/ucb/tr a-z A-Z newfile 3. In the AIX version, this is what happens if the strings are not the same length: /usg/tr '[0-9]' '#' newfile Processed July 12, 1991 TR(1,C) 2 TR(1,C) AIX Commands Reference TR(1,C) This translates each "0" to a # (number sign). Note: If the two character strings are not the same length, the extra characters in the longer one are ignored. 4. In the BSD version, if the strings are not the same length: /usr/ucb/tr 0-9 '#' newfile This translates each digit to a #. Note: If string2 is too short, it is padded to the length of string1 by duplicating its last character. 5. In the AIX version, to translate each digit to a #: /usg/tr '[0-9]' '[#*]' newfile The * tells tr to repeat the # enough times to make the second string as long as the first one. 6. To translate each string of digits to a single #: /usg/tr -s '[0-9]' '[#*]' newfile or, with the BSD version: /usr/ucb/tr -s 0-9 '#' newfile 7. To translate all ASCII characters that are not specified: /usg/tr -c '[ -~]' '[A-_]?' newfile This translates each nonprinting ASCII character to the corresponding control key letter ("\001" translates to "A", "\002" to "B", etc.). ASCII DEL ("\177"), the character that follows "~" (tilde), translates to ?. Or, with the BSD version: /usr/ucb/tr -c ' -~' 'A-_?' newfile 8. To create a list of the words in a file: /usg/tr -cs '[a-z][A-Z]' '[\012*]' newfile or, with the BSD version: /usr/ucb/tr -cs 'a-zA-Z' '\012' newfile RELATED INFORMATION Processed July 12, 1991 TR(1,C) 3 TR(1,C) AIX Commands Reference TR(1,C) See the following commands: "ed, red" and "sh, Rsh." See the ascii file in AIX Operating System Technical Reference. See "Introduction to International Character Support" in Managing the AIX Operating System. Processed July 12, 1991 TR(1,C) 4