📄 tr.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>tr</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="tr"></a> <a name="tag_04_145"></a><!-- tr --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_145_01"></a>NAME</h4><blockquote>tr - translate characters</blockquote><h4><a name="tag_04_145_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>tr</tt> <b>[</b><tt>-c | -C</tt><b>][</b><tt>-s]</tt> <i>string1 string2</i><tt><br><br>tr -s</tt> <b>[</b><tt>-c | -C</tt><b>]</b> <i>string1</i><tt><br><br>tr -d</tt> <b>[</b><tt>-c | -C</tt><b>]</b> <i>string1</i><tt><br><br>tr -ds</tt> <b>[</b><tt>-c | -C</tt><b>]</b> <i>string1 string2</i><tt><br></tt></code></p></blockquote><h4><a name="tag_04_145_03"></a>DESCRIPTION</h4><blockquote><p>The <i>tr</i> utility shall copy the standard input to the standard output with substitution or deletion of selected characters.The options specified and the <i>string1</i> and <i>string2</i> operands shall control translations that occur while copyingcharacters and single-character collating elements.</p></blockquote><h4><a name="tag_04_145_04"></a>OPTIONS</h4><blockquote><p>The <i>tr</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p><p>The following options shall be supported:</p><dl compact><dt><b>-c</b></dt><dd>Complement the set of values specified by <i>string1</i>. See the EXTENDED DESCRIPTION section.</dd><dt><b>-C</b></dt><dd>Complement the set of characters specified by <i>string1</i>. See the EXTENDED DESCRIPTION section.</dd><dt><b>-d</b></dt><dd>Delete all occurrences of input characters that are specified by <i>string1</i>.</dd><dt><b>-s</b></dt><dd>Replace instances of repeated characters with a single character, as described in the EXTENDED DESCRIPTION section.</dd></dl></blockquote><h4><a name="tag_04_145_05"></a>OPERANDS</h4><blockquote><p>The following operands shall be supported:</p><dl compact><dt><i>string1</i>, <i>string2</i></dt><dd><br>Translation control strings. Each string shall represent a set of characters to be converted into an array of characters used forthe translation. For a detailed description of how the strings are interpreted, see the EXTENDED DESCRIPTION section.</dd></dl></blockquote><h4><a name="tag_04_145_06"></a>STDIN</h4><blockquote><p>The standard input can be any type of file.</p></blockquote><h4><a name="tag_04_145_07"></a>INPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_145_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>tr</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_COLLATE</i></dt><dd><br>Determine the locale for the behavior of range expressions and equivalence classes.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments) and the behavior of character classes.</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standarderror.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><h4><a name="tag_04_145_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_145_10"></a>STDOUT</h4><blockquote><p>The <i>tr</i> output shall be identical to the input, with the exception of the specified transformations.</p></blockquote><h4><a name="tag_04_145_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_145_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_145_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>The operands <i>string1</i> and <i>string2</i> (if specified) define two arrays of characters. The constructs in the followinglist can be used to specify characters or single-character collating elements. If any of the constructs result in multi-charactercollating elements, <i>tr</i> shall exclude, without a diagnostic, those multi-character elements from the resulting array.</p><dl compact><dt><i>character</i></dt><dd>Any character not described by one of the conventions below shall represent itself.</dd><dt>\<i>octal</i></dt><dd>Octal sequences can be used to represent characters with specific coded values. An octal sequence shall consist of a backslashfollowed by the longest sequence of one, two, or three-octal-digit characters (01234567). The sequence shall cause the value whoseencoding is represented by the one, two, or three-digit octal integer to be placed into the array. If the size of a byte on thesystem is greater than nine bits, the valid escape sequence used to represent a byte is implementation-defined. Multi-bytecharacters require multiple, concatenated escape sequences of this type, including the leading <tt>'\'</tt> for each byte.</dd><dt>\<i>character</i></dt><dd>The backslash-escape sequences in the Base Definitions volume of IEEE Std 1003.1-2001, Table 5-1, Escape Sequencesand Associated Actions ( <tt>'\\'</tt> , <tt>'\a'</tt> , <tt>'\b'</tt> , <tt>'\f'</tt> , <tt>'\n'</tt> , <tt>'\r'</tt> ,<tt>'\t'</tt> , <tt>'\v'</tt> ) shall be supported. The results of using any other character, other than an octal digit, followingthe backslash are unspecified.</dd><dt><i>c</i>-<i>c</i></dt><dd>In the POSIX locale, this construct shall represent the range of collating elements between the range endpoints (as long asneither endpoint is an octal sequence of the form \<i>octal</i>), inclusive, as defined by the collation sequence. The charactersor collating elements in the range shall be placed in the array in ascending collation sequence. If the second endpoint precedesthe starting endpoint in the collation sequence, it is unspecified whether the range of collating elements is empty, or thisconstruct is treated as invalid. In locales other than the POSIX locale, this construct has unspecified behavior. <p>If either or both of the range endpoints are octal sequences of the form \<i>octal</i>, this shall represent the range ofspecific coded values between the two range endpoints, inclusive.</p></dd><dt>[:<i>class</i>:]</dt><dd>Represents all characters belonging to the defined character class, as defined by the current setting of the <i>LC_CTYPE</i>locale category. The following character class names shall be accepted when specified in <i>string1</i>: <blockquote><table cellpadding="3"><tr valign="top"><td align="left"><p class="tent"><b>alnum</b></p></td><td align="left"><p class="tent"><b>blank</b></p></td><td align="left"><p class="tent"><b>digit</b></p></td><td align="left"><p class="tent"><b>lower</b></p></td><td align="left"><p class="tent"><b>punct</b></p></td><td align="left"><p class="tent"><b>upper</b></p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>alpha</b></p></td><td align="left"><p class="tent"><b>cntrl</b></p></td><td align="left"><p class="tent"><b>graph</b></p></td><td align="left"><p class="tent"><b>print</b></p></td><td align="left"><p class="tent"><b>space</b></p></td><td align="left"><p class="tent"><b>xdigit</b></p></td></tr></table></blockquote><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">In addition, character class expressions of the form [: <i>name</i>:] shall be recognized in those locales where the <i>name</i>keyword has been given a <b>charclass</b> definition in the <i>LC_CTYPE</i> category. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>When both the <b>-d</b> and <b>-s</b> options are specified, any of the character class names shall be accepted in<i>string2</i>. Otherwise, only character class names <b>lower</b> or <b>upper</b> are valid in <i>string2</i> and then only if thecorresponding character class ( <b>upper</b> and <b>lower</b>, respectively) is specified in the same relative position in<i>string1</i>. Such a specification shall be interpreted as a request for case conversion. When [: <i>lower</i>:] appears in<i>string1</i> and [: <i>upper</i>:] appears in <i>string2</i>, the arrays shall contain the characters from the <b>toupper</b>mapping in the <i>LC_CTYPE</i> category of the current locale. When [: <i>upper</i>:] appears in <i>string1</i> and [:<i>lower</i>:] appears in <i>string2</i>, the arrays shall contain the characters from the <b>tolower</b> mapping in the<i>LC_CTYPE</i> category of the current locale. The first character from each mapping pair shall be in the array for <i>string1</i>and the second character from each mapping pair shall be in the array for <i>string2</i> in the same relative position.</p><p>Except for case conversion, the characters specified by a character class expression shall be placed in the array in anunspecified order.</p><p>If the name specified for <i>class</i> does not define a valid character class in the current locale, the behavior isundefined.</p></dd><dt>[=<i>equiv</i>=]</dt><dd>Represents all characters or collating elements belonging to the same equivalence class as <i>equiv</i>, as defined by thecurrent setting of the <i>LC_COLLATE</i> locale category. An equivalence class expression shall be allowed only in <i>string1</i>,or in <i>string2</i> when it is being used by the combined <b>-d</b> and <b>-s</b> options. The characters belonging to theequivalence class shall be placed in the array in an unspecified order.</dd><dt>[<i>x</i>*<i>n</i>]</dt><dd>Represents <i>n</i> repeated occurrences of the character <i>x</i>. Because this expression is used to map multiple characters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -