nrelease - fix/improve livecd
[dragonfly.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. Neither the name of the University nor the names of its contributors
16 .\"    may be used to endorse or promote products derived from this software
17 .\"    without specific prior written permission.
18 .\"
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 .\" SUCH DAMAGE.
30 .\"
31 .\"     @(#)tr.1        8.1 (Berkeley) 6/6/93
32 .\" $FreeBSD: head/usr.bin/tr/tr.1 233510 2012-03-26 15:18:14Z joel $
33 .\"
34 .Dd January 13, 2016
35 .Dt TR 1
36 .Os
37 .Sh NAME
38 .Nm tr
39 .Nd translate characters
40 .Sh SYNOPSIS
41 .Nm
42 .Op Fl Ccsu
43 .Ar string1 string2
44 .Nm
45 .Op Fl Ccu
46 .Fl d
47 .Ar string1
48 .Nm
49 .Op Fl Ccu
50 .Fl s
51 .Ar string1
52 .Nm
53 .Op Fl Ccu
54 .Fl ds
55 .Ar string1 string2
56 .Sh DESCRIPTION
57 The
58 .Nm
59 utility copies the standard input to the standard output with substitution
60 or deletion of selected characters.
61 .Pp
62 The following options are available:
63 .Bl -tag -width Ds
64 .It Fl C
65 Complement the set of characters in
66 .Ar string1 ,
67 that is
68 .Dq Fl C Li ab
69 includes every character except for
70 .Ql a
71 and
72 .Ql b .
73 .It Fl c
74 Same as
75 .Fl C
76 but complement the set of values in
77 .Ar string1 .
78 .It Fl d
79 Delete characters in
80 .Ar string1
81 from the input.
82 .It Fl s
83 Squeeze multiple occurrences of the characters listed in the last
84 operand (either
85 .Ar string1
86 or
87 .Ar string2 )
88 in the input into a single instance of the character.
89 This occurs after all deletion and translation is completed.
90 .It Fl u
91 Guarantee that any output is unbuffered.
92 .El
93 .Pp
94 In the first synopsis form, the characters in
95 .Ar string1
96 are translated into the characters in
97 .Ar string2
98 where the first character in
99 .Ar string1
100 is translated into the first character in
101 .Ar string2
102 and so on.
103 If
104 .Ar string1
105 is longer than
106 .Ar string2 ,
107 the last character found in
108 .Ar string2
109 is duplicated until
110 .Ar string1
111 is exhausted.
112 .Pp
113 In the second synopsis form, the characters in
114 .Ar string1
115 are deleted from the input.
116 .Pp
117 In the third synopsis form, the characters in
118 .Ar string1
119 are compressed as described for the
120 .Fl s
121 option.
122 .Pp
123 In the fourth synopsis form, the characters in
124 .Ar string1
125 are deleted from the input, and the characters in
126 .Ar string2
127 are compressed as described for the
128 .Fl s
129 option.
130 .Pp
131 The following conventions can be used in
132 .Ar string1
133 and
134 .Ar string2
135 to specify sets of characters:
136 .Bl -tag -width [:equiv:]
137 .It character
138 Any character not described by one of the following conventions
139 represents itself.
140 .It \eoctal
141 A backslash followed by 1, 2 or 3 octal digits represents a character
142 with that encoded value.
143 To follow an octal sequence with a digit as a character, left zero-pad
144 the octal sequence to the full 3 octal digits.
145 .It \echaracter
146 A backslash followed by certain special characters maps to special
147 values.
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 For non-octal range endpoints
161 represents the range of characters between the range endpoints, inclusive,
162 in ascending order,
163 as defined by the collation sequence.
164 If either or both of the range endpoints are octal sequences, it
165 represents the range of specific coded values between the
166 range endpoints, inclusive.
167 .Pp
168 .Bf Em
169 See the
170 .Sx COMPATIBILITY
171 section below for an important note regarding
172 differences in the way the current
173 implementation interprets range expressions differently from
174 previous implementations.
175 .Ef
176 .It [:class:]
177 Represents all characters belonging to the defined character class.
178 Class names are:
179 .Bl -column "phonogram"
180 .It "alnum      <alphanumeric characters>"
181 .It "alpha      <alphabetic characters>"
182 .It "blank      <whitespace characters>"
183 .It "cntrl      <control characters>"
184 .It "digit      <numeric characters>"
185 .It "graph      <graphic characters>"
186 .It "ideogram   <ideographic characters>"
187 .It "lower      <lower-case alphabetic characters>"
188 .It "phonogram  <phonographic characters>"
189 .It "print      <printable characters>"
190 .It "punct      <punctuation characters>"
191 .It "rune       <valid characters>"
192 .It "space      <space characters>"
193 .It "special    <special characters>"
194 .It "upper      <upper-case characters>"
195 .It "xdigit     <hexadecimal characters>"
196 .El
197 .Pp
198 .\" All classes may be used in
199 .\" .Ar string1 ,
200 .\" and in
201 .\" .Ar string2
202 .\" when both the
203 .\" .Fl d
204 .\" and
205 .\" .Fl s
206 .\" options are specified.
207 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
208 .\" .Ar string2
209 .\" and then only when the corresponding class (``upper'' for ``lower''
210 .\" and vice-versa) is specified in the same relative position in
211 .\" .Ar string1 .
212 .\" .Pp
213 When
214 .Dq Li [:lower:]
215 appears in
216 .Ar string1
217 and
218 .Dq Li [:upper:]
219 appears in the same relative position in
220 .Ar string2 ,
221 it represents the characters pairs from the
222 .Dv toupper
223 mapping in the
224 .Ev LC_CTYPE
225 category of the current locale.
226 When
227 .Dq Li [:upper:]
228 appears in
229 .Ar string1
230 and
231 .Dq Li [:lower:]
232 appears in the same relative position in
233 .Ar string2 ,
234 it represents the characters pairs from the
235 .Dv tolower
236 mapping in the
237 .Ev LC_CTYPE
238 category of the current locale.
239 .Pp
240 With the exception of case conversion,
241 characters in the classes are in unspecified order.
242 .Pp
243 For specific information as to which
244 .Tn ASCII
245 characters are included
246 in these classes, see
247 .Xr ctype 3
248 and related manual pages.
249 .It [=equiv=]
250 Represents all characters belonging to the same equivalence class as
251 .Ar equiv ,
252 ordered by their encoded values.
253 .It [#*n]
254 Represents
255 .Ar n
256 repeated occurrences of the character represented by
257 .Ar # .
258 This
259 expression is only valid when it occurs in
260 .Ar string2 .
261 If
262 .Ar n
263 is omitted or is zero, it is interpreted as large enough to extend the
264 .Ar string2
265 sequence to the length of
266 .Ar string1 .
267 If
268 .Ar n
269 has a leading zero, it is interpreted as an octal value, otherwise,
270 it is interpreted as a decimal value.
271 .El
272 .Sh ENVIRONMENT
273 The
274 .Ev LANG , LC_ALL , LC_CTYPE
275 and
276 .Ev LC_COLLATE
277 environment variables affect the execution of
278 .Nm
279 as described in
280 .Xr environ 7 .
281 .Sh EXIT STATUS
282 .Ex -std
283 .Sh EXAMPLES
284 The following examples are shown as given to the shell:
285 .Pp
286 Create a list of the words in file1, one per line, where a word is taken to
287 be a maximal string of letters.
288 .Pp
289 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
290 .Pp
291 Translate the contents of file1 to upper-case.
292 .Pp
293 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
294 .Pp
295 (This should be preferred over the traditional
296 .Ux
297 idiom of
298 .Dq Li "tr a-z A-Z" ,
299 since it works correctly in all locales.)
300 .Pp
301 Strip out non-printable characters from file1.
302 .Pp
303 .D1 Li "tr -cd \*q[:print:]\*q < file1"
304 .Pp
305 Remove diacritical marks from all accented variants of the letter
306 .Ql e :
307 .Pp
308 .Dl "tr \*q[=e=]\*q \*qe\*q"
309 .Sh COMPATIBILITY
310 Previous
311 .Fx
312 implementations of
313 .Nm
314 did not order characters in range expressions according to the current
315 locale's collation order, making it possible to convert unaccented Latin
316 characters (esp.\& as found in English text) from upper to lower case using
317 the traditional
318 .Ux
319 idiom of
320 .Dq Li "tr A-Z a-z" .
321 Since
322 .Nm
323 now obeys the locale's collation order, this idiom may not produce
324 correct results when there is not a 1:1 mapping between lower and
325 upper case, or when the order of characters within the two cases differs.
326 As noted in the
327 .Sx EXAMPLES
328 section above, the character class expressions
329 .Dq Li [:lower:]
330 and
331 .Dq Li [:upper:]
332 should be used instead of explicit character ranges like
333 .Dq Li a-z
334 and
335 .Dq Li A-Z .
336 .Pp
337 System V has historically implemented character ranges using the syntax
338 .Dq Li [c-c]
339 instead of the
340 .Dq Li c-c
341 used by historic
342 .Bx
343 implementations and
344 standardized by POSIX.
345 System V shell scripts should work under this implementation as long as
346 the range is intended to map in another range, i.e., the command
347 .Dq Li "tr [a-z] [A-Z]"
348 will work as it will map the
349 .Ql \&[
350 character in
351 .Ar string1
352 to the
353 .Ql \&[
354 character in
355 .Ar string2 .
356 However, if the shell script is deleting or squeezing characters as in
357 the command
358 .Dq Li "tr -d [a-z]" ,
359 the characters
360 .Ql \&[
361 and
362 .Ql \&]
363 will be
364 included in the deletion or compression list which would not have happened
365 under a historic System V implementation.
366 Additionally, any scripts that depended on the sequence
367 .Dq Li a-z
368 to
369 represent the three characters
370 .Ql a ,
371 .Ql \-
372 and
373 .Ql z
374 will have to be
375 rewritten as
376 .Dq Li a\e-z .
377 .Pp
378 The
379 .Nm
380 utility has historically not permitted the manipulation of NUL bytes in
381 its input and, additionally, stripped NUL's from its input stream.
382 This implementation has removed this behavior as a bug.
383 .Pp
384 The
385 .Nm
386 utility has historically been extremely forgiving of syntax errors,
387 for example, the
388 .Fl c
389 and
390 .Fl s
391 options were ignored unless two strings were specified.
392 This implementation will not permit illegal syntax.
393 .Sh STANDARDS
394 The
395 .Nm
396 utility conforms to
397 .St -p1003.1-2001 .
398 The
399 .Dq ideogram ,
400 .Dq phonogram ,
401 .Dq rune ,
402 and
403 .Dq special
404 character classes are extensions.
405 .Pp
406 It should be noted that the feature wherein the last character of
407 .Ar string2
408 is duplicated if
409 .Ar string2
410 has less characters than
411 .Ar string1
412 is permitted by POSIX but is not required.
413 Shell scripts attempting to be portable to other POSIX systems should use
414 the
415 .Dq Li [#*]
416 convention instead of relying on this behavior.
417 The
418 .Fl u
419 option is an extension to the
420 .St -p1003.1-2001
421 standard.