xref: /original-bsd/usr.bin/tr/tr.1 (revision ba762ddc)
1.\" Copyright (c) 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)tr.1	6.4 (Berkeley) 04/23/91
7.\"
8.Dd
9.Dt TR 1
10.Os
11.Sh NAME
12.Nm tr
13.Nd translate characters
14.Sh SYNOPSIS
15.Nm tr
16.Op Fl c
17.Op Fl d | Fl s
18.Ar string1 string2
19.Sh DESCRIPTION
20The tr utility copies the standard input to the standard
21output with substitution or deletion of selected characters.
22The options specified and the
23.Ar string1
24and
25.Ar string2
26operands
27control translations that occur while copying characters.
28.Pp
29The following options are available:
30.Bl -tag -width Ds
31.It Fl c
32Complements the set of characters in string1 with
33respect to the universe of characters whose
34.Tn ISO
35646
36[4] codes are 00 through 0377 octal.
37.It Fl d
38Deletes all input characters in
39.Ar string1 .
40.It Fl s
41Squeezes all output strings of one or more
42instances of a single character in
43.Ar string2
44to a
45single instance of that character.
46Input characters found
47in
48.Ar string1
49are mapped into the corresponding characters
50of
51.Ar string2 .
52When
53.Ar string2
54is shorter than
55.Ar string1 , string2
56is extended to the length of
57.Ar string1
58by duplicating the last character of
59.Ar string2 .
60If
61.Ar string2
62is explicitly a string of zero
63length,
64.Ar string2
65is padded with
66.Tn NUL
67characters.
68.El
69.Pp
70The following operands are available:
71.Bl -tag -width stringx
72.It Ar string1
73.It Ar string2
74Translation character strings.
75.El
76.Pp
77.Pp
78If
79the
80.Fl c
81option is given in conjunction with the
82.Fl d
83option, then only those characters found in
84.Ar string1
85is copied to the standard output.
86.Pp
87The following conventions can be used in
88.Ar string1
89or
90.Ar string2
91or both to specify characters, character ranges, character
92classes, or collating elements:
93.Bl -tag -width [[:equiv:]]
94.It character
95Represents that character.
96.It \eoctal
97A backslash followed by 1, 2, or 3 octal
98digits represents a character with that
99encoded value.
100If a \eoctal sequence is
101followed by digits, the backslash and up to
102three digits are interpreted to prepare a
103character; subsequent digits are interpreted
104as individual characters.
105.It \echaracter
106A backslash followed by any character except
107an octal digit represents that character.
108.It [c-c]
109Represents the range of ordered elements
110between the range endpoints, inclusive.
111.\" ; as
112.\" defined by the current setting of the
113.\" setlocale() category
114.\" .Em LC_COLLATE .
115.\" The collating
116.\" elements are ordered in ascending collating
117.\" sequence, and the first endpoint shall precede
118.\" the second in the collating sequence.
119.It [[:class:]]
120Represents all characters belonging to the
121defined character class.
122.\" as defined by the
123.\" current setting of the setlocale() category
124.\" .Ev LC_CTYPE .
125Allowable names for class are:
126.Bl -column alpha upper lower digit xdigit -offset indent
127alpha  upper  lower  digit  xdigit  alnum
128space  punct  print  graph  cntrl
129.El
130.Pp
131The characters placed in ascending order.
132.\" .Em LC_COLLATE .
133.\" (Characters not defined in the
134.\" current collating sequence are ordered
135.\" according to the collation sequence's rules
136.\" for ordering of undefined characters.)
137.It [[=equiv=]]
138Represents all characters or collating (sorting)
139elements belonging to the same equivalence class
140as equiv.
141.\"
142.\"
143.\" .Em LC_COLLATE .
144If
145there is a secondary ordering within the
146equivalence class, the characters are ordered
147in ascending sequence.
148Otherwise, they are
149ordered after their encoded values.
150.It [[.cs.]]
151Represents a collating symbol.
152Multicharacter
153collating symbols shall be represented as
154collating symbols to distinguish them from a
155string of the same characters.
156.It [x*n]
157Represents n repeated occurrences of the
158character or collating symbol x.
159This
160expression is only valid when it occurs in
161.Ar string2 .
162If n is omitted or is zero, it is
163be interpreted as large enough to extend the
164.Ar string2 Ns -based
165sequence to the length of the
166.Ar string1 Ns -based
167sequence.
168If n has a leading
169zero, it shall be interpreted as an octal
170value.
171Otherwise, it shall be interpreted as
172a decimal value.
173.El
174.Pp
175Characters belonging to an equivalence class occupy the same
176position in the sequence, ordered after secondary ordering.
177.Pp
178The
179.Nm tr
180utility exits with one of the following values:
181.Bl -tag -width Ds
182.It 0
183All input was processed successfully.
184.It 1
185An error occurred.
186.El
187.Sh STANDARDS
188The
189.Nm tr
190utility is expected to be
191.Tn POSIX
1921003.2 compatible.
193