Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)
User Commands (t - u) tr(1)
[a*number]
Stands for number repetitions of a. number is considered to be in decimal unless the
first digit of number is 0; then it is considered to be in octal. Because this expression is
used to map multiple characters to one character, it is only valid when it occurs in
string2.Ifnumber is omitted or is 0 (zero), it is interpreted as large enough to extend
the string2-based sequence to the length of the string1-based sequence.
[=equiv=]
Represents all characters or collating elements belonging to the equivalence class
specified by equiv,asdefined by the LC_COLLATE locale category. An equivalence
class expression can be used for string1 or string2 only when used in combination with
the -d and -s flags. (For more information, see the reference page for the locale file.)
[:class:] Represents all characters belonging to the defined character class, as defined by the
current setting of the LC_CTYPE locale category. The following character class
names are accepted when specified in string1:
alnum cntrl lower space
alpha digit print upper
blank graph punct xdigit
When the -d and -s flags are specified together, any of the character class names are
accepted in string2; otherwise, only character class names lower or upper are
accepted in string2 and then only if the corresponding character class (upper and
lower, respectively) is specified in the same relative position in string1. Such a
specification is interpreted as a request for case conversion.
When [:lower:] appears in string1 and [:upper:] appears in string2, the arrays contain
the characters from the toupper mapping in the LC_CTYPE category of the current
locale. When [:upper:] appears in string1 and [:lower:] appears in string2, the arrays
contain the characters from the tolower mapping in the LC_CTYPE category of the
current locale.
The first character from each mapping pair is in the array for string1 and the second
character from each mapping pair is in the array for string2 in the same relative posi-
tion. (For more information about possible character class settings, see the reference
page for sh.)
Use the escape character \ (backslash) to remove the special meaning from any character in a
string. Use the \ (backslash) followed by 1, 2, or 3 octal digits for the code of a character.
If an ordinary digit (representing itself) is to follow an octal sequence, the octal sequence must
use the full three digits to avoid ambiguity.
When string2 is shorter than string1, a difference results between historical System V and BSD
systems. A BSD system pads string2 with the last character found in string2. Thus, it is possible
to do the following:
tr 0123456789 d
The preceding command translates all digits to the letter d. A portable application cannot rely on
the BSD behavior; it would have to code the example in the following way:
tr 0123456789 ’[d*]’
Despite their similarity to regular expressions, string arguments used by tr are not regular expres-
sions.
The tr command correctly processes NULL characters in its input stream. NULL characters can
be stripped using the following command:
tr -d ’\000’
527188-004 Hewlett-Packard Company 9−19