⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tr.1

📁 早期freebsd实现
💻 1
字号:
.\" Copyright (c) 1991, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" This code is derived from software contributed to Berkeley by.\" the Institute of Electrical and Electronics Engineers, Inc..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"     @(#)tr.1	8.1 (Berkeley) 6/6/93.\".Dd June 6, 1993.Dt TR 1.Os.Sh NAME.Nm tr.Nd translate characters.Sh SYNOPSIS.Nm tr.Op Fl cs.Ar string1 string2.Nm tr.Op Fl c.Fl d.Ar string1.Nm tr.Op Fl c.Fl s.Ar string1.Nm tr.Op Fl c.Fl ds.Ar string1 string2.Sh DESCRIPTIONThe.Nm trutility copies the standard input to the standard output with substitutionor deletion of selected characters..PpThe following options are available:.Bl -tag -width Ds.It Fl cComplements the set of characters in.Ar string1 ,that is ``-c ab'' includes every character except for ``a'' and ``b''..It Fl dThe.Fl doption causes characters to be deleted from the input..It Fl sThe.Fl soption squeezes multiple occurrences of the characters listed in the lastoperand (either.Ar string1or.Ar string2 )in the input into a single instance of the character.This occurs after all deletion and translation is completed..El.PpIn the first synopsis form, the characters in.Ar string1are translated into the characters in.Ar string2where the first character in.Ar string1is translated into the first character in.Ar string2and so on.If.Ar string1is longer than.Ar string2 ,the last character found in.Ar string2is duplicated until.Ar string1is exhausted..PpIn the second synopsis form, the characters in.Ar string1are deleted from the input..PpIn the third synopsis form, the characters in.Ar string1are compressed as described for the.Fl soption..PpIn the fourth synopsis form, the characters in.Ar string1are deleted from the input, and the characters in.Ar string2are compressed as described for the.Fl soption..PpThe following conventions can be used in.Ar string1and.Ar string2to specify sets of characters:.Bl -tag -width [:equiv:].It characterAny character not described by one of the following conventionsrepresents itself..It \eoctalA backslash followed by 1, 2 or 3 octal digits represents a characterwith that encoded value.To follow an octal sequence with a digit as a character, left zero-padthe octal sequence to the full 3 octal digits..It \echaracterA backslash followed by certain special characters maps to specialvalues..sp.Bl -column.It \ea	<alert character>.It \eb	<backspace>.It \ef	<form-feed>.It \en	<newline>.It \er	<carriage return>.It \et	<tab>.It \ev	<vertical tab>.El.spA backslash followed by any other character maps to that character..It c-cRepresents the range of characters between the range endpoints, inclusively..It [:class:]Represents all characters belonging to the defined character class.Class names are:.sp.Bl -column.It alnum	<alphanumeric characters>.It alpha	<alphabetic characters>.It cntrl	<control characters>.It digit	<numeric characters>.It graph	<graphic characters>.It lower	<lower-case alphabetic characters>.It print	<printable characters>.It punct	<punctuation characters>.It space	<space characters>.It upper	<upper-case characters>.It xdigit	<hexadecimal characters>.El.Pp\." All classes may be used in\." .Ar string1 ,\." and in\." .Ar string2\." when both the\." .Fl d\." and\." .Fl s\." options are specified.\." Otherwise, only the classes ``upper'' and ``lower'' may be used in\." .Ar string2\." and then only when the corresponding class (``upper'' for ``lower''\." and vice-versa) is specified in the same relative position in\." .Ar string1 .\." .PpWith the exception of the ``upper'' and ``lower'' classes, charactersin the classes are in unspecified order.In the ``upper'' and ``lower'' classes, characters are entered inascending order..PpFor specific information as to which ASCII characters are includedin these classes, see.Xr ctype 3and related manual pages..It [=equiv=]Represents all characters or collating (sorting) elements belonging tothe same equivalence class as.Ar equiv .Ifthere is a secondary ordering within the equivalence class, the charactersare ordered in ascending sequence.Otherwise, they are ordered after their encoded values. An example of an equivalence class might be ``c'' and ``ch'' in Spanish;English has no equivalence classes..It [#*n]Represents.Ar nrepeated occurrences of the character represented by.Ar # .Thisexpression is only valid when it occurs in.Ar string2 .If.Ar nis omitted or is zero, it is be interpreted as large enough to extend.Ar string2sequence to the length of.Ar string1 .If.Ar nhas a leading zero, it is interpreted as an octal value, otherwise,it's interpreted as a decimal value..El.PpThe.Nm trutility exits 0 on success, and >0 if an error occurs..Sh EXAMPLESThe following examples are shown as given to the shell:.spCreate a list of the words in file1, one per line, where a word is taken tobe a maximal string of letters..sp.D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1".spTranslate the contents of file1 to upper-case..sp.D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1".spStrip out non-printable characters from file1..sp.D1 Li "tr -cd \*q[:print:]\*q < file1".Sh COMPATIBILITYSystem V has historically implemented character ranges using the syntax``[c-c]'' instead of the ``c-c'' used by historic BSD implementations andstandardized by POSIX.System V shell scripts should work under this implementation as long asthe range is intended to map in another range, i.e. the command``tr [a-z] [A-Z]'' will work as it will map the ``['' character in.Ar string1to the ``['' character in.Ar string2.However, if the shell script is deleting or squeezing characters as inthe command ``tr -d [a-z]'', the characters ``['' and ``]'' will be included in the deletion or compression list which would not have happenedunder an historic System V implementation.Additionally, any scripts that depended on the sequence ``a-z'' torepresent the three characters ``a'', ``-'' and ``z'' will have to berewritten as ``a\e-z''..PpThe.Nm trutility has historically not permitted the manipulation of NUL bytes inits input and, additionally, stripped NUL's from its input stream.This implementation has removed this behavior as a bug..PpThe.Nm trutility has historically been extremely forgiving of syntax errors,for example, the.Fl cand.Fl soptions were ignored unless two strings were specified.This implementation will not permit illegal syntax..Sh STANDARDSThe.Nm trutility is expected to be.St -p1003.2compatible.It should be noted that the feature wherein the last character of.Ar string2is duplicated if.Ar string2has less characters than.Ar string1is permitted by POSIX but is not required.Shell scripts attempting to be portable to other POSIX systems should usethe ``[#*]'' convention instead of relying on this behavior.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -