BSD 3 development
[unix-history] / usr / man / man1 / tr.1
CommitLineData
e6817382
BJ
1.TH TR 1
2.SH NAME
3tr \- translate characters
4.SH SYNOPSIS
5.B tr
6[
7.B \-cds
8] [ string1 [ string2 ] ]
9.SH DESCRIPTION
10.I Tr
11copies the standard input to the standard output with
12substitution or deletion of selected characters.
13Input characters found in
14.I string1
15are mapped into the corresponding characters of
16.IR string2 .
17When
18.I string2
19is short it is padded to the length of
20.I string1
21by duplicating its last character.
22Any combination of the options
23.B \-cds
24may be used:
25.B \-c
26complements the set of characters in
27.I string1
28with respect to the universe of characters
29whose ASCII codes are 01 through 0377 octal;
30.B \-d
31deletes all input characters in
32.I string1;
33.B \-s
34squeezes all strings of repeated output characters that are
35in
36.I string2
37to single characters.
38.PP
39In either string the notation
40.IB a \- b
41means a range of characters from
42.I a
43to
44.I b
45in increasing ASCII order.
46The character
47`\e' followed by 1, 2 or 3 octal digits stands for the
48character whose ASCII code is given by those digits.
49A `\e' followed by any other character stands
50for that character.
51.PP
52The following example creates a list of all
53the words in `file1' one per line in `file2',
54where a word is taken to be a maximal string of alphabetics.
55The second string is quoted
56to protect `\e' from the Shell.
57012 is the ASCII code for newline.
58.IP
59tr \-cs A\-Za\-z \'\e012\' <file1 >file2
60.SH "SEE ALSO"
61ed(1), ascii(7)
62.SH BUGS
63Won't handle ASCII NUL in
64.I string1
65or
66.I string2;
67always deletes NUL from input.