bb0578dc40fc0e7c611c9efd38de7f9213ecb453
[games.git] / usr.bin / tr / tr.1
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)tr.1        8.1 (Berkeley) 6/6/93
36 .\" $FreeBSD: src/usr.bin/tr/tr.1,v 1.5.2.7 2002/07/29 12:59:33 tjr Exp $
37 .\" $DragonFly: src/usr.bin/tr/tr.1,v 1.3 2006/02/17 19:39:12 swildner Exp $
38 .\"
39 .Dd October 11, 1997
40 .Dt TR 1
41 .Os
42 .Sh NAME
43 .Nm tr
44 .Nd translate characters
45 .Sh SYNOPSIS
46 .Nm
47 .Op Fl csu
48 .Ar string1 string2
49 .Nm
50 .Op Fl cu
51 .Fl d
52 .Ar string1
53 .Nm
54 .Op Fl cu
55 .Fl s
56 .Ar string1
57 .Nm
58 .Op Fl cu
59 .Fl ds
60 .Ar string1 string2
61 .Sh DESCRIPTION
62 The
63 .Nm
64 utility copies the standard input to the standard output with substitution
65 or deletion of selected characters.
66 .Pp
67 The following options are available:
68 .Bl -tag -width Ds
69 .It Fl c
70 Complements the set of characters in
71 .Ar string1 ,
72 that is ``-c ab'' includes every character except for ``a'' and ``b''.
73 .It Fl d
74 The
75 .Fl d
76 option causes characters to be deleted from the input.
77 .It Fl s
78 The
79 .Fl s
80 option squeezes multiple occurrences of the characters listed in the last
81 operand (either
82 .Ar string1
83 or
84 .Ar string2 )
85 in the input into a single instance of the character.
86 This occurs after all deletion and translation is completed.
87 .It Fl u
88 The
89 .Fl u
90 option guarantees that any output is unbuffered.
91 .El
92 .Pp
93 In the first synopsis form, the characters in
94 .Ar string1
95 are translated into the characters in
96 .Ar string2
97 where the first character in
98 .Ar string1
99 is translated into the first character in
100 .Ar string2
101 and so on.
102 If
103 .Ar string1
104 is longer than
105 .Ar string2 ,
106 the last character found in
107 .Ar string2
108 is duplicated until
109 .Ar string1
110 is exhausted.
111 .Pp
112 In the second synopsis form, the characters in
113 .Ar string1
114 are deleted from the input.
115 .Pp
116 In the third synopsis form, the characters in
117 .Ar string1
118 are compressed as described for the
119 .Fl s
120 option.
121 .Pp
122 In the fourth synopsis form, the characters in
123 .Ar string1
124 are deleted from the input, and the characters in
125 .Ar string2
126 are compressed as described for the
127 .Fl s
128 option.
129 .Pp
130 The following conventions can be used in
131 .Ar string1
132 and
133 .Ar string2
134 to specify sets of characters:
135 .Bl -tag -width [:equiv:]
136 .It character
137 Any character not described by one of the following conventions
138 represents itself.
139 .It \eoctal
140 A backslash followed by 1, 2 or 3 octal digits represents a character
141 with that encoded value.
142 To follow an octal sequence with a digit as a character, left zero-pad
143 the octal sequence to the full 3 octal digits.
144 .It \echaracter
145 A backslash followed by certain special characters maps to special
146 values.
147 .Pp
148 .Bl -column "\ea"
149 .It "\ea        <alert character>
150 .It "\eb        <backspace>
151 .It "\ef        <form-feed>
152 .It "\en        <newline>
153 .It "\er        <carriage return>
154 .It "\et        <tab>
155 .It "\ev        <vertical tab>
156 .El
157 .Pp
158 A backslash followed by any other character maps to that character.
159 .It c-c
160 Represents the range of characters between the range endpoints, inclusively.
161 .It [:class:]
162 Represents all characters belonging to the defined character class.
163 Class names are:
164 .Pp
165 .Bl -column "xdigit"
166 .It "alnum      <alphanumeric characters>
167 .It "alpha      <alphabetic characters>
168 .It "cntrl      <control characters>
169 .It "digit      <numeric characters>
170 .It "graph      <graphic characters>
171 .It "lower      <lower-case alphabetic characters>
172 .It "print      <printable characters>
173 .It "punct      <punctuation characters>
174 .It "space      <space characters>
175 .It "upper      <upper-case characters>
176 .It "xdigit     <hexadecimal characters>
177 .El
178 .Pp
179 .\" All classes may be used in
180 .\" .Ar string1 ,
181 .\" and in
182 .\" .Ar string2
183 .\" when both the
184 .\" .Fl d
185 .\" and
186 .\" .Fl s
187 .\" options are specified.
188 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
189 .\" .Ar string2
190 .\" and then only when the corresponding class (``upper'' for ``lower''
191 .\" and vice-versa) is specified in the same relative position in
192 .\" .Ar string1 .
193 .\" .Pp
194 With the exception of the ``upper'' and ``lower'' classes, characters
195 in the classes are in unspecified order.
196 In the ``upper'' and ``lower'' classes, characters are entered in
197 ascending order.
198 .Pp
199 For specific information as to which ASCII characters are included
200 in these classes, see
201 .Xr ctype 3
202 and related manual pages.
203 .It [=equiv=]
204 Represents all characters belonging to the same equivalence class as
205 .Ar equiv ,
206 ordered by their encoded values.
207 .It [#*n]
208 Represents
209 .Ar n
210 repeated occurrences of the character represented by
211 .Ar # .
212 This
213 expression is only valid when it occurs in
214 .Ar string2 .
215 If
216 .Ar n
217 is omitted or is zero, it is be interpreted as large enough to extend
218 .Ar string2
219 sequence to the length of
220 .Ar string1 .
221 If
222 .Ar n
223 has a leading zero, it is interpreted as an octal value, otherwise,
224 it's interpreted as a decimal value.
225 .El
226 .Sh ENVIRONMENT
227 The
228 .Ev LANG ,
229 .Ev LC_ALL ,
230 .Ev LC_CTYPE
231 and
232 .Ev LC_COLLATE
233 environment variables affect the execution of
234 .Nm
235 as described in
236 .Xr environ 7 .
237 .Sh EXAMPLES
238 The following examples are shown as given to the shell:
239 .Pp
240 Create a list of the words in file1, one per line, where a word is taken to
241 be a maximal string of letters.
242 .Pp
243 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
244 .Pp
245 Translate the contents of file1 to upper-case.
246 .Pp
247 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
248 .Pp
249 Strip out non-printable characters from file1.
250 .Pp
251 .D1 Li "tr -cd \*q[:print:]\*q < file1"
252 .Pp
253 Remove diacritical marks from all accented variants of the letter
254 .Sq e :
255 .Pp
256 .Dl "tr \*q[=e=]\*q \*qe\*q"
257 .Sh DIAGNOSTICS
258 .Ex -std
259 .Sh COMPATIBILITY
260 System V has historically implemented character ranges using the syntax
261 ``[c-c]'' instead of the ``c-c'' used by historic
262 .Bx
263 implementations and
264 standardized by POSIX.
265 System V shell scripts should work under this implementation as long as
266 the range is intended to map in another range, i.e. the command
267 ``tr [a-z] [A-Z]'' will work as it will map the ``['' character in
268 .Ar string1
269 to the ``['' character in
270 .Ar string2 .
271 However, if the shell script is deleting or squeezing characters as in
272 the command ``tr -d [a-z]'', the characters ``['' and ``]'' will be
273 included in the deletion or compression list which would not have happened
274 under an historic System V implementation.
275 Additionally, any scripts that depended on the sequence ``a-z'' to
276 represent the three characters ``a'', ``-'' and ``z'' will have to be
277 rewritten as ``a\e-z''.
278 .Pp
279 The
280 .Nm
281 utility has historically not permitted the manipulation of NUL bytes in
282 its input and, additionally, stripped NUL's from its input stream.
283 This implementation has removed this behavior as a bug.
284 .Pp
285 The
286 .Nm
287 utility has historically been extremely forgiving of syntax errors,
288 for example, the
289 .Fl c
290 and
291 .Fl s
292 options were ignored unless two strings were specified.
293 This implementation will not permit illegal syntax.
294 .Sh STANDARDS
295 The
296 .Nm
297 utility is expected to be
298 .St -p1003.2
299 compatible.
300 It should be noted that the feature wherein the last character of
301 .Ar string2
302 is duplicated if
303 .Ar string2
304 has less characters than
305 .Ar string1
306 is permitted by POSIX but is not required.
307 Shell scripts attempting to be portable to other POSIX systems should use
308 the ``[#*]'' convention instead of relying on this behavior.
309 The
310 .Fl u
311 option is an extension to the
312 .St -p1003.2
313 standard.