]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/tr/tr.1
This commit was generated by cvs2svn to compensate for changes in r66525,
[FreeBSD/FreeBSD.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$
37 .\"
38 .Dd October 11, 1997
39 .Dt TR 1
40 .Os
41 .Sh NAME
42 .Nm tr
43 .Nd translate characters
44 .Sh SYNOPSIS
45 .Nm tr
46 .Op Fl csu
47 .Ar string1 string2
48 .Nm tr
49 .Op Fl cu
50 .Fl d
51 .Ar string1
52 .Nm tr
53 .Op Fl cu
54 .Fl s
55 .Ar string1
56 .Nm tr
57 .Op Fl cu
58 .Fl ds
59 .Ar string1 string2
60 .Sh DESCRIPTION
61 The
62 .Nm
63 utility copies the standard input to the standard output with substitution
64 or deletion of selected characters.
65 .Pp
66 The following options are available:
67 .Bl -tag -width Ds
68 .It Fl c
69 Complements the set of characters in
70 .Ar string1 ,
71 that is ``-c ab'' includes every character except for ``a'' and ``b''.
72 .It Fl d
73 The
74 .Fl d
75 option causes characters to be deleted from the input.
76 .It Fl s
77 The
78 .Fl s
79 option squeezes multiple occurrences of the characters listed in the last
80 operand (either
81 .Ar string1
82 or
83 .Ar string2 )
84 in the input into a single instance of the character.
85 This occurs after all deletion and translation is completed.
86 .It Fl u
87 The
88 .Fl u
89 option guarantees that any output is unbuffered.
90 .El
91 .Pp
92 In the first synopsis form, the characters in
93 .Ar string1
94 are translated into the characters in
95 .Ar string2
96 where the first character in
97 .Ar string1
98 is translated into the first character in
99 .Ar string2
100 and so on.
101 If
102 .Ar string1
103 is longer than
104 .Ar string2 ,
105 the last character found in
106 .Ar string2
107 is duplicated until
108 .Ar string1
109 is exhausted.
110 .Pp
111 In the second synopsis form, the characters in
112 .Ar string1
113 are deleted from the input.
114 .Pp
115 In the third synopsis form, the characters in
116 .Ar string1
117 are compressed as described for the
118 .Fl s
119 option.
120 .Pp
121 In the fourth synopsis form, the characters in
122 .Ar string1
123 are deleted from the input, and the characters in
124 .Ar string2
125 are compressed as described for the
126 .Fl s
127 option.
128 .Pp
129 The following conventions can be used in
130 .Ar string1
131 and
132 .Ar string2
133 to specify sets of characters:
134 .Bl -tag -width [:equiv:]
135 .It character
136 Any character not described by one of the following conventions
137 represents itself.
138 .It \eoctal
139 A backslash followed by 1, 2 or 3 octal digits represents a character
140 with that encoded value.
141 To follow an octal sequence with a digit as a character, left zero-pad
142 the octal sequence to the full 3 octal digits.
143 .It \echaracter
144 A backslash followed by certain special characters maps to special
145 values.
146 .sp
147 .Bl -column
148 .It \ea <alert character>
149 .It \eb <backspace>
150 .It \ef <form-feed>
151 .It \en <newline>
152 .It \er <carriage return>
153 .It \et <tab>
154 .It \ev <vertical tab>
155 .El
156 .sp
157 A backslash followed by any other character maps to that character.
158 .It c-c
159 Represents the range of characters between the range endpoints, inclusively.
160 .It [:class:]
161 Represents all characters belonging to the defined character class.
162 Class names are:
163 .sp
164 .Bl -column
165 .It alnum       <alphanumeric characters>
166 .It alpha       <alphabetic characters>
167 .It cntrl       <control characters>
168 .It digit       <numeric characters>
169 .It graph       <graphic characters>
170 .It lower       <lower-case alphabetic characters>
171 .It print       <printable characters>
172 .It punct       <punctuation characters>
173 .It space       <space characters>
174 .It upper       <upper-case characters>
175 .It xdigit      <hexadecimal characters>
176 .El
177 .Pp
178 \." All classes may be used in
179 \." .Ar string1 ,
180 \." and in
181 \." .Ar string2
182 \." when both the
183 \." .Fl d
184 \." and
185 \." .Fl s
186 \." options are specified.
187 \." Otherwise, only the classes ``upper'' and ``lower'' may be used in
188 \." .Ar string2
189 \." and then only when the corresponding class (``upper'' for ``lower''
190 \." and vice-versa) is specified in the same relative position in
191 \." .Ar string1 .
192 \." .Pp
193 With the exception of the ``upper'' and ``lower'' classes, characters
194 in the classes are in unspecified order.
195 In the ``upper'' and ``lower'' classes, characters are entered in
196 ascending order.
197 .Pp
198 For specific information as to which ASCII characters are included
199 in these classes, see
200 .Xr ctype 3
201 and related manual pages.
202 .It [=equiv=]
203 Represents all characters or collating (sorting) elements belonging to
204 the same equivalence class as
205 .Ar equiv .
206 If
207 there is a secondary ordering within the equivalence class, the characters
208 are ordered in ascending sequence.
209 Otherwise, they are ordered after their encoded values. 
210 An example of an equivalence class might be ``c'' and ``ch'' in Spanish;
211 English has no equivalence classes.
212 .It [#*n]
213 Represents
214 .Ar n
215 repeated occurrences of the character represented by
216 .Ar # .
217 This
218 expression is only valid when it occurs in
219 .Ar string2 .
220 If
221 .Ar n
222 is omitted or is zero, it is be interpreted as large enough to extend
223 .Ar string2
224 sequence to the length of
225 .Ar string1 .
226 If
227 .Ar n
228 has a leading zero, it is interpreted as an octal value, otherwise,
229 it's interpreted as a decimal value.
230 .El
231 .Sh DIAGNOSTICS
232 The
233 .Nm
234 utility exits 0 on success, and >0 if an error occurs.
235 .Sh EXAMPLES
236 The following examples are shown as given to the shell:
237 .sp
238 Create a list of the words in file1, one per line, where a word is taken to
239 be a maximal string of letters.
240 .sp
241 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
242 .sp
243 Translate the contents of file1 to upper-case.
244 .sp
245 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
246 .sp
247 Strip out non-printable characters from file1.
248 .sp
249 .D1 Li "tr -cd \*q[:print:]\*q < file1"
250 .Sh COMPATIBILITY
251 System V has historically implemented character ranges using the syntax
252 ``[c-c]'' instead of the ``c-c'' used by historic BSD implementations and
253 standardized by POSIX.
254 System V shell scripts should work under this implementation as long as
255 the range is intended to map in another range, i.e. the command
256 ``tr [a-z] [A-Z]'' will work as it will map the ``['' character in
257 .Ar string1
258 to the ``['' character in
259 .Ar string2.
260 However, if the shell script is deleting or squeezing characters as in
261 the command ``tr -d [a-z]'', the characters ``['' and ``]'' will be 
262 included in the deletion or compression list which would not have happened
263 under an historic System V implementation.
264 Additionally, any scripts that depended on the sequence ``a-z'' to
265 represent the three characters ``a'', ``-'' and ``z'' will have to be
266 rewritten as ``a\e-z''.
267 .Pp
268 The
269 .Nm
270 utility has historically not permitted the manipulation of NUL bytes in
271 its input and, additionally, stripped NUL's from its input stream.
272 This implementation has removed this behavior as a bug.
273 .Pp
274 The
275 .Nm
276 utility has historically been extremely forgiving of syntax errors,
277 for example, the
278 .Fl c
279 and
280 .Fl s
281 options were ignored unless two strings were specified.
282 This implementation will not permit illegal syntax.
283 .Sh STANDARDS
284 The
285 .Nm
286 utility is expected to be
287 .St -p1003.2
288 compatible.
289 It should be noted that the feature wherein the last character of
290 .Ar string2
291 is duplicated if
292 .Ar string2
293 has less characters than
294 .Ar string1
295 is permitted by POSIX but is not required.
296 Shell scripts attempting to be portable to other POSIX systems should use
297 the ``[#*]'' convention instead of relying on this behavior.
298 The
299 .Fl u
300 option is an extension to the
301 .St -p1003.2
302 standard.