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