Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
tr(1) OSS Shell and Utilities Reference Manual
EXAMPLES
1. To translate braces into parentheses, enter:
tr ’{}’ ’()’
This translates each { (left brace) to a ( (left parenthesis) and each } (right brace) to )
(right parenthesis). All other characters remain unchanged and are sent to standard out-
put.
2. To translate lowercase ASCII characters to uppercase, enter:
tr ’[:lower:]’ ’[:upper:]’ < infile > outfile
3. To translate each digit to a # (number sign), enter:
tr ’0-9’ ’[#*]’ < infile > outfile
The * (asterisk) tells tr to repeat the # (number sign) enough times to make the second
string as long as the first one.
4. To translate each string of digits to a single # (number sign), enter:
tr -s ’0-9’ ’[#*]’ < infile > outfile
5. To translate all ASCII characters that are not specified, enter:
tr -c ’[ -˜\177]’ ’[A-_?]’ < infile > outfile
This translates each nonprinting ASCII character to the corresponding control key letter
(\001 translates to A, \002 to B, and so on). ASCII DEL (\177), the character that follows
~(tilde), translates to a ? (question mark).
6. To create a list of all words in file1 one per line in file2, where a word is taken to be a
maximal string of letters, enter:
tr -cs ’[:alpha:]’ ’[\n*]’ < file1 > file2
7. To use an equivalence class to identify accented variants of the base character e in file1,
which are stripped of diacritical marks and written to file2,enter:
tr ’[=e=]’ ’[e*]’ < file1 > file2
Specifying the -A flag improves ASCII performance.
RELATED INFORMATION
Commands: sh(1).
9−20 Hewlett-Packard Company 527188-021