📄 sort.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>sort</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="sort"></a> <a name="tag_04_131"></a><!-- sort --> <!--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_131_01"></a>NAME</h4><blockquote>sort - sort, merge, or sequence check text files</blockquote><h4><a name="tag_04_131_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>sort</tt> <b>[</b><tt>-m</tt><b>][</b><tt>-o</tt> <i>output</i><b>][</b><tt>-bdfinru</tt><b>][</b><tt>-t</tt><i>char</i><b>][</b><tt>-k</tt> <i>keydef</i><b>]</b><tt>...</tt> <b>[</b><i>file</i><tt>...</tt><b>]</b><tt><br><br>sort -c</tt> <b>[</b><tt>-bdfinru</tt><b>][</b><tt>-t</tt> <i>char</i><b>][</b><tt>-k</tt><i>keydef</i><b>][</b><i>file</i><b>]</b><tt><br></tt></code></p></blockquote><h4><a name="tag_04_131_03"></a>DESCRIPTION</h4><blockquote><p>The <i>sort</i> utility shall perform one of the following functions:</p><ol><li><p>Sort lines of all the named files together and write the result to the specified output.</p></li><li><p>Merge lines of all the named (presorted) files together and write the result to the specified output.</p></li><li><p>Check that a single input file is correctly presorted.</p></li></ol><p>Comparisons shall be based on one or more sort keys extracted from each line of input (or, if no sort keys are specified, theentire line up to, but not including, the terminating <newline>), and shall be performed using the collating sequence of thecurrent locale.</p></blockquote><h4><a name="tag_04_131_04"></a>OPTIONS</h4><blockquote><p>The <i>sort</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>, and the <b>-k</b> <i>keydef</i> option shouldfollow the <b>-b</b>, <b>-d</b>, <b>-f</b>, <b>-i</b>, <b>-n</b>, and <b>-r</b> options.</p><p>The following options shall be supported:</p><dl compact><dt><b>-c</b></dt><dd>Check that the single input file is ordered as specified by the arguments and the collating sequence of the current locale. Nooutput shall be produced; only the exit code shall be affected.</dd><dt><b>-m</b></dt><dd>Merge only; the input file shall be assumed to be already sorted.</dd><dt><b>-o </b> <i>output</i></dt><dd>Specify the name of an output file to be used instead of the standard output. This file can be the same as one of the input<i>file</i>s.</dd><dt><b>-u</b></dt><dd>Unique: suppress all but one in each set of lines having equal keys. If used with the <b>-c</b> option, check that there are nolines with duplicate keys, in addition to checking that the input file is sorted.</dd></dl><p>The following options shall override the default ordering rules. When ordering options appear independent of any key fieldspecifications, the requested field ordering rules shall be applied globally to all sort keys. When attached to a specific key (see<b>-k</b>), the specified ordering options shall override all global ordering options for that key.</p><dl compact><dt><b>-d</b></dt><dd>Specify that only <blank>s and alphanumeric characters, according to the current setting of <i>LC_CTYPE ,</i> shall besignificant in comparisons. The behavior is undefined for a sort key to which <b>-i</b> or <b>-n</b> also applies.</dd><dt><b>-f</b></dt><dd>Consider all lowercase characters that have uppercase equivalents, according to the current setting of <i>LC_CTYPE ,</i> to bethe uppercase equivalent for the purposes of comparison.</dd><dt><b>-i</b></dt><dd>Ignore all characters that are non-printable, according to the current setting of <i>LC_CTYPE .</i></dd><dt><b>-n</b></dt><dd>Restrict the sort key to an initial numeric string, consisting of optional <blank>s, optional minus sign, and zero ormore digits with an optional radix character and thousands separators (as defined in the current locale), which shall be sorted byarithmetic value. An empty digit string shall be treated as zero. Leading zeros and signs on zeros shall not affect ordering.</dd><dt><b>-r</b></dt><dd>Reverse the sense of comparisons.</dd></dl><p>The treatment of field separators can be altered using the options:</p><dl compact><dt><b>-b</b></dt><dd>Ignore leading <blank>s when determining the starting and ending positions of a restricted sort key. If the <b>-b</b>option is specified before the first <b>-k</b> option, it shall be applied to all <b>-k</b> options. Otherwise, the <b>-b</b>option can be attached independently to each <b>-k</b> <i>field_start</i> or <i>field_end</i> option-argument (see below).</dd><dt><b>-t </b> <i>char</i></dt><dd>Use <i>char</i> as the field separator character; <i>char</i> shall not be considered to be part of a field (although it can beincluded in a sort key). Each occurrence of <i>char</i> shall be significant (for example, <<i>char</i>><<i>char</i>>delimits an empty field). If <b>-t</b> is not specified, <blank>s shall be used as default field separators; each maximalnon-empty sequence of <blank>s that follows a non- <blank> shall be a field separator.</dd></dl><p>Sort keys can be specified using the options:</p><dl compact><dt><b>-k </b> <i>keydef</i></dt><dd>The <i>keydef</i> argument is a restricted sort key field definition. The format of this definition is: <pre><i>field_start</i><b>[</b><i>type</i><b>][</b><tt>,</tt><i>field_end</i><b>[</b><i>type</i><b>]]</b></pre><p>where <i>field_start</i> and <i>field_end</i> define a key field restricted to a portion of the line (see the EXTENDEDDESCRIPTION section), and <i>type</i> is a modifier from the list of characters <tt>'b'</tt> , <tt>'d'</tt> , <tt>'f'</tt> ,<tt>'i'</tt> , <tt>'n'</tt> , <tt>'r'</tt> . The <tt>'b'</tt> modifier shall behave like the <b>-b</b> option, but shall apply onlyto the <i>field_start</i> or <i>field_end</i> to which it is attached. The other modifiers shall behave like the correspondingoptions, but shall apply only to the key field to which they are attached; they shall have this effect if specified with<i>field_start</i>, <i>field_end</i>, or both. If any modifier is attached to a <i>field_start</i> or to a <i>field_end</i>, nooption shall apply to either. Implementations shall support at least nine occurrences of the <b>-k</b> option, which shall besignificant in command line order. If no <b>-k</b> option is specified, a default sort key of the entire line shall be used.</p><p>When there are multiple key fields, later keys shall be compared only after all earlier keys compare equal. Except when the<b>-u</b> option is specified, lines that otherwise compare equal shall be ordered as if none of the options <b>-d</b>, <b>-f</b>,<b>-i</b>, <b>-n</b>, or <b>-k</b> were present (but with <b>-r</b> still in effect, if it was specified) and with all bytes in thelines significant to the comparison. The order in which lines that still compare equal are written is unspecified.</p></dd></dl></blockquote><h4><a name="tag_04_131_05"></a>OPERANDS</h4><blockquote><p>The following operand shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A pathname of a file to be sorted, merged, or checked. If no <i>file</i> operands are specified, or if a <i>file</i> operand is<tt>'-'</tt> , the standard input shall be used.</dd></dl></blockquote><h4><a name="tag_04_131_06"></a>STDIN</h4><blockquote><p>The standard input shall be used only if no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt> .See the INPUT FILES section.</p></blockquote><h4><a name="tag_04_131_07"></a>INPUT FILES</h4><blockquote><p>The input files shall be text files, except that the <i>sort</i> utility shall add a <newline> to the end of a file endingwith an incomplete last line.</p></blockquote><h4><a name="tag_04_131_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>sort</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 ordering rules.</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 input files) and the behavior of character classification for the <b>-b</b>,<b>-d</b>, <b>-f</b>, <b>-i</b>, and <b>-n</b> options.</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>LC_NUMERIC</i></dt><dd><br>Determine the locale for the definition of the radix character and thousands separator for the <b>-n</b> option.</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_131_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_131_10"></a>STDOUT</h4><blockquote><p>Unless the <b>-o</b> or <b>-c</b> options are in effect, the standard output shall contain the sorted input.</p></blockquote><h4><a name="tag_04_131_11"></a>STDERR</h4><blockquote><p>The standard error shall be used for diagnostic messages. A warning message about correcting an incomplete last line of an inputfile may be generated, but need not affect the final exit status.</p></blockquote><h4><a name="tag_04_131_12"></a>OUTPUT FILES</h4><blockquote><p>If the <b>-o</b> option is in effect, the sorted input shall be written to the file <i>output</i>.</p></blockquote><h4><a name="tag_04_131_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>The notation:</p><pre><tt>-k</tt> <i>field_start</i><b>[</b><i>type</i><b>][</b><tt>,</tt><i>field_end</i><b>[</b><i>type</i><b>]]</b></pre><p>shall define a key field that begins at <i>field_start</i> and ends at <i>field_end</i> inclusive, unless <i>field_start</i>falls beyond the end of the line or after <i>field_end</i>, in which case the key field is empty. A missing <i>field_end</i> shallmean the last character of the line.</p><p>A field comprises a maximal sequence of non-separating characters and, in the absence of option <b>-t</b>, any preceding fieldseparator.</p><p>The <i>field_start</i> portion of the <i>keydef</i> option-argument shall have the form:</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -