HP-UX Reference (11i v3 07/02) - 1 User Commands N-Z (vol 2)

t
tr(1) tr(1)
NAME
tr - translate characters
SYNOPSIS
tr [-Acs] string1 string2
tr -s [-Ac] string1
tr -d [-Ac] string1
tr -ds [-Ac] string1 string1
DESCRIPTION
tr copies 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. If necessary,
string1 and string2 can be quoted to avoid pattern matching by the shell.
tr recognizes the following command line options:
-A Translates on a byte-by-byte basis. When this flag is specified
tr
does not support
extended characters.
-c Complements the set of characters in string1, which is the set of all characters in the
current character set, as defined by the current setting of LC_CTYPE, except for
those actually specified in the string1 argument. These characters are placed in the
array in ascending collation sequence, as defined by the current setting of
LC_COLLATE .
-d Deletes all occurrences of input characters or collating elements found in the array
specified in string1.
If -c and -d are both specified, all characters except those specified by string1 are
deleted. The contents of string2 are ignored, unless
-s is also specified. Note, how-
ever, that the same string cannot be used for both the -d and the -s flags; when
both flags are specified, both string1 (used for deletion) and string2 (used for squeez-
ing) are required.
If
-d is not specified, each input character or collating element found in the array
specified by string1 is replaced by the character or collating element in the same rela-
tive position specified by string2.
-s Replaces any character specified in string1 that occurs as a string of two or more
repeating characters as a single instance of the character in string2.
If the string2 contains a character class, the argument’s array contains all of the char-
acters in that character class. For example:
tr -s [:space:]
In a case conversion, however, the string2 array contains only those characters
defined as the second characters in each of the toupper or tolower character
pairs, as appropriate. For example:
tr -s [:upper:]’’[:lower:]
The following abbreviation conventions can be used to introduce ranges of characters, repeated characters
or single-character collating elements into the strings:
c1-c2 or
[c1-c2]
Stands for the range of collating elements c1 through c2, inclusive, as defined by the
current setting of the LC_COLLATE locale category.
[:class:]or
[[:class:]]
Stands for all the characters belonging to the defined character class, as defined by the
current setting of LC_CTYPE locale category. The following character class names
will be accepted when specified in string1: alnum, alpha, blank, cntrl.
digit, graph, lower, print, punct, space, upper,orxdigit, Character
classes are expanded in collation order.
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
HP-UX 11i Version 3: February 2007 1 Hewlett-Packard Company 339