19b50d902SRodney W. Grimes.\" Copyright (c) 1991, 1993 29b50d902SRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 39b50d902SRodney W. Grimes.\" 49b50d902SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 59b50d902SRodney W. Grimes.\" the Institute of Electrical and Electronics Engineers, Inc. 69b50d902SRodney W. Grimes.\" 79b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 89b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions 99b50d902SRodney W. Grimes.\" are met: 109b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 119b50d902SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 129b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 139b50d902SRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 149b50d902SRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 159b50d902SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 169b50d902SRodney W. Grimes.\" must display the following acknowledgement: 179b50d902SRodney W. Grimes.\" This product includes software developed by the University of 189b50d902SRodney W. Grimes.\" California, Berkeley and its contributors. 199b50d902SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 209b50d902SRodney W. Grimes.\" may be used to endorse or promote products derived from this software 219b50d902SRodney W. Grimes.\" without specific prior written permission. 229b50d902SRodney W. Grimes.\" 239b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 249b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 259b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 269b50d902SRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 279b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 289b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 299b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 309b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 319b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 329b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 339b50d902SRodney W. Grimes.\" SUCH DAMAGE. 349b50d902SRodney W. Grimes.\" 359b50d902SRodney W. Grimes.\" @(#)tr.1 8.1 (Berkeley) 6/6/93 36c3aac50fSPeter Wemm.\" $FreeBSD$ 379b50d902SRodney W. Grimes.\" 3869bd8767SWolfgang Helbig.Dd October 11, 1997 399b50d902SRodney W. Grimes.Dt TR 1 409b50d902SRodney W. Grimes.Os 419b50d902SRodney W. Grimes.Sh NAME 429b50d902SRodney W. Grimes.Nm tr 439b50d902SRodney W. Grimes.Nd translate characters 449b50d902SRodney W. Grimes.Sh SYNOPSIS 459b50d902SRodney W. Grimes.Nm tr 4669bd8767SWolfgang Helbig.Op Fl csu 479b50d902SRodney W. Grimes.Ar string1 string2 489b50d902SRodney W. Grimes.Nm tr 4969bd8767SWolfgang Helbig.Op Fl cu 509b50d902SRodney W. Grimes.Fl d 519b50d902SRodney W. Grimes.Ar string1 529b50d902SRodney W. Grimes.Nm tr 5369bd8767SWolfgang Helbig.Op Fl cu 549b50d902SRodney W. Grimes.Fl s 559b50d902SRodney W. Grimes.Ar string1 569b50d902SRodney W. Grimes.Nm tr 5769bd8767SWolfgang Helbig.Op Fl cu 589b50d902SRodney W. Grimes.Fl ds 599b50d902SRodney W. Grimes.Ar string1 string2 609b50d902SRodney W. Grimes.Sh DESCRIPTION 619b50d902SRodney W. GrimesThe 62af647767SPhilippe Charnier.Nm 639b50d902SRodney W. Grimesutility copies the standard input to the standard output with substitution 649b50d902SRodney W. Grimesor deletion of selected characters. 659b50d902SRodney W. Grimes.Pp 669b50d902SRodney W. GrimesThe following options are available: 679b50d902SRodney W. Grimes.Bl -tag -width Ds 689b50d902SRodney W. Grimes.It Fl c 699b50d902SRodney W. GrimesComplements the set of characters in 709b50d902SRodney W. Grimes.Ar string1 , 719b50d902SRodney W. Grimesthat is ``-c ab'' includes every character except for ``a'' and ``b''. 729b50d902SRodney W. Grimes.It Fl d 739b50d902SRodney W. GrimesThe 749b50d902SRodney W. Grimes.Fl d 759b50d902SRodney W. Grimesoption causes characters to be deleted from the input. 769b50d902SRodney W. Grimes.It Fl s 779b50d902SRodney W. GrimesThe 789b50d902SRodney W. Grimes.Fl s 799b50d902SRodney W. Grimesoption squeezes multiple occurrences of the characters listed in the last 809b50d902SRodney W. Grimesoperand (either 819b50d902SRodney W. Grimes.Ar string1 829b50d902SRodney W. Grimesor 839b50d902SRodney W. Grimes.Ar string2 ) 849b50d902SRodney W. Grimesin the input into a single instance of the character. 859b50d902SRodney W. GrimesThis occurs after all deletion and translation is completed. 8669bd8767SWolfgang Helbig.It Fl u 8769bd8767SWolfgang HelbigThe 8869bd8767SWolfgang Helbig.Fl u 8969bd8767SWolfgang Helbigoption guarantees that any output is unbuffered. 909b50d902SRodney W. Grimes.El 919b50d902SRodney W. Grimes.Pp 929b50d902SRodney W. GrimesIn the first synopsis form, the characters in 939b50d902SRodney W. Grimes.Ar string1 949b50d902SRodney W. Grimesare translated into the characters in 959b50d902SRodney W. Grimes.Ar string2 969b50d902SRodney W. Grimeswhere the first character in 979b50d902SRodney W. Grimes.Ar string1 989b50d902SRodney W. Grimesis translated into the first character in 999b50d902SRodney W. Grimes.Ar string2 1009b50d902SRodney W. Grimesand so on. 1019b50d902SRodney W. GrimesIf 1029b50d902SRodney W. Grimes.Ar string1 1039b50d902SRodney W. Grimesis longer than 1049b50d902SRodney W. Grimes.Ar string2 , 1059b50d902SRodney W. Grimesthe last character found in 1069b50d902SRodney W. Grimes.Ar string2 1079b50d902SRodney W. Grimesis duplicated until 1089b50d902SRodney W. Grimes.Ar string1 1099b50d902SRodney W. Grimesis exhausted. 1109b50d902SRodney W. Grimes.Pp 1119b50d902SRodney W. GrimesIn the second synopsis form, the characters in 1129b50d902SRodney W. Grimes.Ar string1 1139b50d902SRodney W. Grimesare deleted from the input. 1149b50d902SRodney W. Grimes.Pp 1159b50d902SRodney W. GrimesIn the third synopsis form, the characters in 1169b50d902SRodney W. Grimes.Ar string1 1179b50d902SRodney W. Grimesare compressed as described for the 1189b50d902SRodney W. Grimes.Fl s 1199b50d902SRodney W. Grimesoption. 1209b50d902SRodney W. Grimes.Pp 1219b50d902SRodney W. GrimesIn the fourth synopsis form, the characters in 1229b50d902SRodney W. Grimes.Ar string1 1239b50d902SRodney W. Grimesare deleted from the input, and the characters in 1249b50d902SRodney W. Grimes.Ar string2 1259b50d902SRodney W. Grimesare compressed as described for the 1269b50d902SRodney W. Grimes.Fl s 1279b50d902SRodney W. Grimesoption. 1289b50d902SRodney W. Grimes.Pp 1299b50d902SRodney W. GrimesThe following conventions can be used in 1309b50d902SRodney W. Grimes.Ar string1 1319b50d902SRodney W. Grimesand 1329b50d902SRodney W. Grimes.Ar string2 1339b50d902SRodney W. Grimesto specify sets of characters: 1349b50d902SRodney W. Grimes.Bl -tag -width [:equiv:] 1359b50d902SRodney W. Grimes.It character 1369b50d902SRodney W. GrimesAny character not described by one of the following conventions 1379b50d902SRodney W. Grimesrepresents itself. 1389b50d902SRodney W. Grimes.It \eoctal 1399b50d902SRodney W. GrimesA backslash followed by 1, 2 or 3 octal digits represents a character 1409b50d902SRodney W. Grimeswith that encoded value. 1419b50d902SRodney W. GrimesTo follow an octal sequence with a digit as a character, left zero-pad 1429b50d902SRodney W. Grimesthe octal sequence to the full 3 octal digits. 1439b50d902SRodney W. Grimes.It \echaracter 1449b50d902SRodney W. GrimesA backslash followed by certain special characters maps to special 1459b50d902SRodney W. Grimesvalues. 1469b50d902SRodney W. Grimes.sp 1479b50d902SRodney W. Grimes.Bl -column 1489b50d902SRodney W. Grimes.It \ea <alert character> 1499b50d902SRodney W. Grimes.It \eb <backspace> 1509b50d902SRodney W. Grimes.It \ef <form-feed> 1519b50d902SRodney W. Grimes.It \en <newline> 1529b50d902SRodney W. Grimes.It \er <carriage return> 1539b50d902SRodney W. Grimes.It \et <tab> 1549b50d902SRodney W. Grimes.It \ev <vertical tab> 1559b50d902SRodney W. Grimes.El 1569b50d902SRodney W. Grimes.sp 1579b50d902SRodney W. GrimesA backslash followed by any other character maps to that character. 1589b50d902SRodney W. Grimes.It c-c 1599b50d902SRodney W. GrimesRepresents the range of characters between the range endpoints, inclusively. 1609b50d902SRodney W. Grimes.It [:class:] 1619b50d902SRodney W. GrimesRepresents all characters belonging to the defined character class. 1629b50d902SRodney W. GrimesClass names are: 1639b50d902SRodney W. Grimes.sp 1649b50d902SRodney W. Grimes.Bl -column 1659b50d902SRodney W. Grimes.It alnum <alphanumeric characters> 1669b50d902SRodney W. Grimes.It alpha <alphabetic characters> 1679b50d902SRodney W. Grimes.It cntrl <control characters> 1689b50d902SRodney W. Grimes.It digit <numeric characters> 1699b50d902SRodney W. Grimes.It graph <graphic characters> 1709b50d902SRodney W. Grimes.It lower <lower-case alphabetic characters> 1719b50d902SRodney W. Grimes.It print <printable characters> 1729b50d902SRodney W. Grimes.It punct <punctuation characters> 1739b50d902SRodney W. Grimes.It space <space characters> 1749b50d902SRodney W. Grimes.It upper <upper-case characters> 1759b50d902SRodney W. Grimes.It xdigit <hexadecimal characters> 1769b50d902SRodney W. Grimes.El 1779b50d902SRodney W. Grimes.Pp 1789b50d902SRodney W. Grimes\." All classes may be used in 1799b50d902SRodney W. Grimes\." .Ar string1 , 1809b50d902SRodney W. Grimes\." and in 1819b50d902SRodney W. Grimes\." .Ar string2 1829b50d902SRodney W. Grimes\." when both the 1839b50d902SRodney W. Grimes\." .Fl d 1849b50d902SRodney W. Grimes\." and 1859b50d902SRodney W. Grimes\." .Fl s 1869b50d902SRodney W. Grimes\." options are specified. 1879b50d902SRodney W. Grimes\." Otherwise, only the classes ``upper'' and ``lower'' may be used in 1889b50d902SRodney W. Grimes\." .Ar string2 1899b50d902SRodney W. Grimes\." and then only when the corresponding class (``upper'' for ``lower'' 1909b50d902SRodney W. Grimes\." and vice-versa) is specified in the same relative position in 1919b50d902SRodney W. Grimes\." .Ar string1 . 1929b50d902SRodney W. Grimes\." .Pp 1939b50d902SRodney W. GrimesWith the exception of the ``upper'' and ``lower'' classes, characters 1949b50d902SRodney W. Grimesin the classes are in unspecified order. 1959b50d902SRodney W. GrimesIn the ``upper'' and ``lower'' classes, characters are entered in 1969b50d902SRodney W. Grimesascending order. 1979b50d902SRodney W. Grimes.Pp 1989b50d902SRodney W. GrimesFor specific information as to which ASCII characters are included 1999b50d902SRodney W. Grimesin these classes, see 2009b50d902SRodney W. Grimes.Xr ctype 3 2019b50d902SRodney W. Grimesand related manual pages. 2029b50d902SRodney W. Grimes.It [=equiv=] 2039b50d902SRodney W. GrimesRepresents all characters or collating (sorting) elements belonging to 2049b50d902SRodney W. Grimesthe same equivalence class as 2059b50d902SRodney W. Grimes.Ar equiv . 2069b50d902SRodney W. GrimesIf 2079b50d902SRodney W. Grimesthere is a secondary ordering within the equivalence class, the characters 2089b50d902SRodney W. Grimesare ordered in ascending sequence. 2099b50d902SRodney W. GrimesOtherwise, they are ordered after their encoded values. 2109b50d902SRodney W. GrimesAn example of an equivalence class might be ``c'' and ``ch'' in Spanish; 2119b50d902SRodney W. GrimesEnglish has no equivalence classes. 2129b50d902SRodney W. Grimes.It [#*n] 2139b50d902SRodney W. GrimesRepresents 2149b50d902SRodney W. Grimes.Ar n 2159b50d902SRodney W. Grimesrepeated occurrences of the character represented by 2169b50d902SRodney W. Grimes.Ar # . 2179b50d902SRodney W. GrimesThis 2189b50d902SRodney W. Grimesexpression is only valid when it occurs in 2199b50d902SRodney W. Grimes.Ar string2 . 2209b50d902SRodney W. GrimesIf 2219b50d902SRodney W. Grimes.Ar n 2229b50d902SRodney W. Grimesis omitted or is zero, it is be interpreted as large enough to extend 2239b50d902SRodney W. Grimes.Ar string2 2249b50d902SRodney W. Grimessequence to the length of 2259b50d902SRodney W. Grimes.Ar string1 . 2269b50d902SRodney W. GrimesIf 2279b50d902SRodney W. Grimes.Ar n 2289b50d902SRodney W. Grimeshas a leading zero, it is interpreted as an octal value, otherwise, 2299b50d902SRodney W. Grimesit's interpreted as a decimal value. 2309b50d902SRodney W. Grimes.El 231dbb9d8f8SPhilippe Charnier.Sh DIAGNOSTICS 2329b50d902SRodney W. GrimesThe 233af647767SPhilippe Charnier.Nm 2349b50d902SRodney W. Grimesutility exits 0 on success, and >0 if an error occurs. 2359b50d902SRodney W. Grimes.Sh EXAMPLES 2369b50d902SRodney W. GrimesThe following examples are shown as given to the shell: 2379b50d902SRodney W. Grimes.sp 2389b50d902SRodney W. GrimesCreate a list of the words in file1, one per line, where a word is taken to 2399b50d902SRodney W. Grimesbe a maximal string of letters. 2409b50d902SRodney W. Grimes.sp 2419b50d902SRodney W. Grimes.D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1" 2429b50d902SRodney W. Grimes.sp 2439b50d902SRodney W. GrimesTranslate the contents of file1 to upper-case. 2449b50d902SRodney W. Grimes.sp 2459b50d902SRodney W. Grimes.D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1" 2469b50d902SRodney W. Grimes.sp 2479b50d902SRodney W. GrimesStrip out non-printable characters from file1. 2489b50d902SRodney W. Grimes.sp 2499b50d902SRodney W. Grimes.D1 Li "tr -cd \*q[:print:]\*q < file1" 2509b50d902SRodney W. Grimes.Sh COMPATIBILITY 2519b50d902SRodney W. GrimesSystem V has historically implemented character ranges using the syntax 2529b50d902SRodney W. Grimes``[c-c]'' instead of the ``c-c'' used by historic BSD implementations and 2539b50d902SRodney W. Grimesstandardized by POSIX. 2549b50d902SRodney W. GrimesSystem V shell scripts should work under this implementation as long as 2559b50d902SRodney W. Grimesthe range is intended to map in another range, i.e. the command 2569b50d902SRodney W. Grimes``tr [a-z] [A-Z]'' will work as it will map the ``['' character in 2579b50d902SRodney W. Grimes.Ar string1 2589b50d902SRodney W. Grimesto the ``['' character in 2599b50d902SRodney W. Grimes.Ar string2. 2609b50d902SRodney W. GrimesHowever, if the shell script is deleting or squeezing characters as in 2619b50d902SRodney W. Grimesthe command ``tr -d [a-z]'', the characters ``['' and ``]'' will be 2629b50d902SRodney W. Grimesincluded in the deletion or compression list which would not have happened 2639b50d902SRodney W. Grimesunder an historic System V implementation. 2649b50d902SRodney W. GrimesAdditionally, any scripts that depended on the sequence ``a-z'' to 2659b50d902SRodney W. Grimesrepresent the three characters ``a'', ``-'' and ``z'' will have to be 2669b50d902SRodney W. Grimesrewritten as ``a\e-z''. 2679b50d902SRodney W. Grimes.Pp 2689b50d902SRodney W. GrimesThe 269af647767SPhilippe Charnier.Nm 2709b50d902SRodney W. Grimesutility has historically not permitted the manipulation of NUL bytes in 2719b50d902SRodney W. Grimesits input and, additionally, stripped NUL's from its input stream. 2729b50d902SRodney W. GrimesThis implementation has removed this behavior as a bug. 2739b50d902SRodney W. Grimes.Pp 2749b50d902SRodney W. GrimesThe 275af647767SPhilippe Charnier.Nm 2769b50d902SRodney W. Grimesutility has historically been extremely forgiving of syntax errors, 2779b50d902SRodney W. Grimesfor example, the 2789b50d902SRodney W. Grimes.Fl c 2799b50d902SRodney W. Grimesand 2809b50d902SRodney W. Grimes.Fl s 2819b50d902SRodney W. Grimesoptions were ignored unless two strings were specified. 2829b50d902SRodney W. GrimesThis implementation will not permit illegal syntax. 2839b50d902SRodney W. Grimes.Sh STANDARDS 2849b50d902SRodney W. GrimesThe 285af647767SPhilippe Charnier.Nm 2869b50d902SRodney W. Grimesutility is expected to be 2879b50d902SRodney W. Grimes.St -p1003.2 2889b50d902SRodney W. Grimescompatible. 2899b50d902SRodney W. GrimesIt should be noted that the feature wherein the last character of 2909b50d902SRodney W. Grimes.Ar string2 2919b50d902SRodney W. Grimesis duplicated if 2929b50d902SRodney W. Grimes.Ar string2 2939b50d902SRodney W. Grimeshas less characters than 2949b50d902SRodney W. Grimes.Ar string1 2959b50d902SRodney W. Grimesis permitted by POSIX but is not required. 2969b50d902SRodney W. GrimesShell scripts attempting to be portable to other POSIX systems should use 2979b50d902SRodney W. Grimesthe ``[#*]'' convention instead of relying on this behavior. 29869bd8767SWolfgang HelbigThe 29969bd8767SWolfgang Helbig.Fl u 30069bd8767SWolfgang Helbigoption is an extension to the 30169bd8767SWolfgang Helbig.St -p1003.2 30269bd8767SWolfgang Helbigstandard. 303