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