tr(1)
_________________________________________________________________
tr Command
translate characters
_________________________________________________________________
SYNTAX
tr [ -cds ] [ string1 [ string2 ] ]
DESCRIPTION
Tr copies the standard input to the standard output, substituting
or deleting selected characters. Input characters found in
string1 are mapped into the corresponding characters of string2.
You can use any combination of these options:
-c Complements the set of characters in string1 with 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 in
string2 to single characters.
The following abbreviation conventions introduce ranges of
characters or repeated characters into the strings:
[a-z] Stands for the string of characters whose ASCII codes run
from character a to character z, inclusive.
[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.
Use the escape character \ as in the shell to remove special
meaning from any character in a string. In addition, \ followed
by one, two, or three octal digits stands for the character whose
ASCII code is given by those digits.
_________________________________________________________________
EXAMPLES
$ cat infile
aaaabbbccccccc
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
tr(1)
$ tr -s "[a-z]" "[A-Z]" <infile > outfile
$ cat outfile
ABC
$
This example causes all lower case letters in the infile to be
converted to capital letters in the outfile. The -s switch
causes repeated output characters to be "squeezed".
$ cat infile2
Mary Wadsmith 23 11/10
Tim Simon 28 1/15
Karen Adams 24 3/9
$ tr -d "[0-9]/" <infile2 >outfile2
Mary Wadsmith
Tim Simon
Karen Adams
$
This example causes all numeric values and slashes to be deleted
from infile1. All other values are left alone. The output goes
to outfile1.
$ cat infile3
Jim Wang - employee number 32465
Grant Stanley - employee number 98757
Cindy Eddy - employee number 76578
Mark Hoopes - employee number 78657
$ tr -cs "[0-9]" "[\012*]" <infile3 >outfile3
$ cat outfile3
32465
98757
76578
78657
$
This example causes all values in the infile that are not in
string1, [0-9], to be converted to newlines ( 12 is the ascii
value for newline). All of the newlines are "squeezed", and all
values that are in string1 are left alone (because of the -c
option).
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
tr(1)
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 new-line.
tr -cs "[A-Z][a-z]" "[\012*]" <file1 >file2
_________________________________________________________________
SEE ALSO
ed(1), sh(1).
ascii(5) in the Programmer's Reference for the DG/UX System
BUGS
Will not handle ASCII NUL in string1 or string2; always deletes
NUL from input.
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)