TR(1) UNIX Programmer's Manual TR(1)
tr - translate characters
S
\bSY
\bYN
\bNO
\bOP
\bPS
\bSI
\bIS
\bS
t
\btr
\br [ -
\b-c
\bcd
\bds
\bs ] [ string1 [ string2 ] ]
D
\bDE
\bES
\bSC
\bCR
\bRI
\bIP
\bPT
\bTI
\bIO
\bON
\bN
_
\bT_
\br copies the standard input to the standard output with
substitution or deletion of selected characters. Input
characters found in _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 are mapped into the correspond-
ing characters of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2. When _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2 is short it is pad-
ded to the length of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 by duplicating its last charac-
ter. Any combination of the options -
\b-c
\bcd
\bds
\bs may be used: -
\b-c
\bc
complements the set of characters in _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 with respect to
the universe of characters whose ASCII codes are 01 through
0377 octal; -
\b-d
\bd deletes all input characters in _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1; -
\b-s
\bs
squeezes all strings of repeated output characters that are
in _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2 to single characters.
In either string the notation _
\ba-
\b-_
\bb means a range of charac-
ters from _
\ba to _
\bb in increasing ASCII order. The character
`\' followed by 1, 2 or 3 octal digits stands for the char-
acter whose ASCII code is given by those digits. A `\' fol-
lowed by any other character stands for that character.
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 second string is
quoted to protect `\' from the Shell. 012 is the ASCII code
tr -cs A-Za-z '\012' <file1 >file2
S
\bSE
\bEE
\bE A
\bAL
\bLS
\bSO
\bO
ed(1), ascii(7), expand(1)
Won't handle ASCII NUL in _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 or _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2; always deletes
Printed 7/9/88 April 29, 1985 1