tr(C)


tr -- translate characters

Syntax

tr [ -cs ] string1 string2

tr -s [ -c ] string1

tr -d [ -c ] string1

tr -ds [ -c ] string1 string2

Description

The tr command copies the standard input to the standard output with substitution or deletion of selected characters. Input characters found in string1 are mapped into the corresponding characters of string2. Any combination of the options -cds may be used:

-c
Complements the set of characters in string1 with respect to the universe of characters whose ASCII codes are 001 through 377 octal.

-d
Deletes all input characters in string1.

-s
Squeezes all strings of repeated output characters that are in string2 to single characters.
tr understands the option -- to be the option delimiter. string1 and string2 are defined as two strings of characters. In addition to literal strings of characters, tr understands the following constructs:

\octal
backslash escaped sequence followed by 1, 2 or 3 octal digits represents the character whose ASCII code is defined by that sequence of digits

\character
backslash escaped sequence for any of the file format notation (\\, \a, \b, \f, \n, \r, \t, \v).

c-c
range of collating elements between the range endpoints, inclusive (as defined by the current setting of the LC_COLLATE locale category). The characters or collating elements in the range are placed in the array in ascending collation sequence. The first endpoint must precede the second endpoint in the current collation order.

[:class:]
a character belonging to the LC_CTYPE character class. Supported classes are:

alnum blank digit lower punct upper
alpha cntrl graph print space xdigit

All of these are acceptable when specified in string1. When both the -d and -s options are specified, all of the class names are acceptable in string2. If the two options are not specified, only lower and upper are acceptable in string2. (See localedef(C) for further information.)


[=equiv=]
Characters belonging to the LC_COLLATE equivalence class equiv. An equivalence class expression can be used in string1, and in string2 when the command line includes the -d and -s options. (See localedef(C) for further information.)

[a*n]
Stands for n repetitions of a. If the first digit of n is 0, n is considered octal; otherwise, n is taken to be decimal. A zero or missing n is taken to be huge; this facility is useful for padding string2.
The following example creates a list of all the words in file1, one per line in file2, where a word is taken to be a maximal string of alphabetics. The strings are quoted to protect the special characters from interpretation by the shell; 012 is the ASCII code for newline:

tr -cs "A-Za-z" "[\012*]" <file1 >file2

This example translates all lower-case characters in file1 to upper-case and writes the output to file2.

tr "[:lower:]" "[:upper:]" < file1 > file2

See also

ascii(M), ed(C), locale(M), localedef(C), sh(C)

Standards conformance

tr is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005