Open System Services Shell and Utilities Reference Manual (G06.25+, H06.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:] <inle > outle
3. To translate each digit to a # (number sign), enter:
tr 0-9’’[#*] <inle > outle
The * (asterisk) tells tr to repeat the # (number sign) enough times to make the second
string as long as the rst one.
4. To translate each string of digits to a single # (number sign), enter:
tr -s 0-9’’[#*] <inle > outle
5. To translate all ASCII characters that are not specied, enter:
tr -c [-˜\177]’’[A-_?] <inle > outle
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 le1 one per line in le2, where a word is taken to be a
maximal string of letters, enter:
tr -cs [:alpha:]’’[\n*]< le1 > le2
7. To use an equivalence class to identify accented variants of the base character e in le1,
which are stripped of diacritical marks and written to le2,enter:
tr [=e=]’’[e*]< le1 > le2
Specifying the -A ag improves ASCII performance.
RELATED INFORMATION
Commands: sh(1).
920 Hewlett-Packard Company 527188-003