📄 sort.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>sort</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_2030"> </a>NAME</h4><blockquote>sort - sort, merge or sequence check text files</blockquote><h4><a name = "tag_001_014_2031"> </a>SYNOPSIS</h4><blockquote><pre><code>sort <b>[</b>-m<b>][</b>-o <i>output</i><b>][</b>-bdfinru<b>][</b>-t <i>char</i><b>][</b>-k <i>keydef</i><b>]</b>...<b>[</b>-z <i>recsz</i><b>][</b><i>file</i>...<b>]</b>sort -c <b>[</b>-bdfinru<b>][</b>-t <i>char</i><b>][</b>-k <i>keydef</i><b>]</b>...<b>[</b>-z <i>recsz</i><b>][</b><i>file</i>...<b>]</b>sort <b>[</b>-mu<b>][</b>-o <i>output</i><b>][</b>-bdfir<b>][</b>-t <i>char</i><b>][</b>+<i>pos1</i><b>[</b>-<i>pos2</i><b>]]</b>...<b>[</b>-z <i>recsz</i><b>][</b><i>file</i>...<b>]</b>sort -c<b>[</b>-u<b>][</b>-bdfinr<b>][</b>-t <i>char</i><b>][</b>+<i>pos1</i><b>[</b>-<i>pos2</i><b>]]</b>...<b>[</b>-z <i>recsz</i><b>][</b><i>file</i><b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_2032"> </a>DESCRIPTION</h4><blockquote>The<i>sort</i>utility performs one of the following functions:<ol><p><li>Sorts lines of all the named files togetherand writes the result to the specified output.<p><li>Merges lines of all the named (presorted) files togetherand writes the result to the specified output.<p><li>Checks that a single input file is correctly presorted.<p></ol><p>Comparisons are based on one or moresort keys extracted from each line of input(or the entire line if no sort keys are specified),and are performed using the collating sequence of the current locale.</blockquote><h4><a name = "tag_001_014_2033"> </a>OPTIONS</h4><blockquote>The<i>sort</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> ,except that the notation<i>+pos1</i><i>-pos2</i>uses a non-standard prefix andmulti-digit option names in the obsolescent versions, the<b>-o</b> <i>output</i>option is recognised after a<i>file</i>operand as an obsolescentfeature in both versions where the<b>-c</b>option is not specified,and the<b>-k</b> <i>keydef</i>option should follow the<b>-b</b>,<b>-d</b>,<b>-f</b>,<b>-i</b>,<b>-n</b>and<b>-r</b>options.<p>The following options are supported:<dl compact><dt><b>-c</b><dd>Check that the single input file is ordered as specified bythe arguments and thecollating sequence of the current locale.No output is produced; only the exit code is affected.<dt><b>-m</b><dd>Merge only;the input file is assumed to be already sorted.<dt><b>-o </b><i>output</i><dd>Specify the name of an output fileto be used instead of the standard output.This file can be the same as one of the input<i>file</i>s.<dt><b>-u</b><dd>Unique: suppress all but one in eachset of lines having equal keys.If used with the<b>-c</b>option, check that there are no lines with duplicate keys,in addition to checking that the input file is sorted.<dt><b>-z </b><i>recsz</i><dd>The size of the longest line readin the sort phase is recorded so that buffers of the correct sizecan be allocated during the merge phase.If the sort phase is omitted via the<b>-c</b>or<b>-m</b>options, a system-dependent default size will be used.Lines longer than the buffer size will cause<i>sort</i>to terminate abnormally.Supplying the actual number of bytes in the longest lineto be merged (or some larger value)will prevent abnormal termination.</dl><p>The following options override the default ordering rules.When ordering options appear independent ofany key field specifications, the requested field ordering rules areapplied globally to all sort keys.When attached to a specific key (see<b>-k</b>),the specified ordering options override all global ordering optionsfor that key.In the obsolescent forms, if one or more of these options follows a<i>+pos1</i>option, it will affect only the key field specified by that preceding option.<dl compact><dt><b>-d</b><dd>Specify that only blank charactersand alphanumeric characters, according to the current setting ofLC_CTYPE, are significant in comparisons.The behaviour is undefined for a sort key to which<b>-i</b>or<b>-n</b>also applies.<dt><b>-f</b><dd>Consider all lower-case characters that have upper-caseequivalents, according to the current setting of LC_CTYPE,to be the upper-case equivalent for the purposes of comparison.<dt><b>-i</b><dd>Ignore all characters that are non-printable,according to the current setting of LC_CTYPE.<dt><b>-n</b><dd>Restrict the sort key toan initial numeric string,consisting of optionalblank characters,optional minus sign,and zero or more digits with an optionalradix character and thousands separators(as defined in the current locale),which will be sorted by arithmetic value.An empty digit string is treated as zero.Leading zeros and signs on zeros do not affect ordering.<dt><b>-r</b><dd>Reverse the sense of comparisons.</dl><p>The treatment of field separators can be altered using the options:<dl compact><dt><b>-b</b><dd>Ignore leadingblank characterswhen determining the starting and endingpositions of a restricted sort key.If the<b>-b</b>option is specified before the first<b>-k</b>option, it is 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).<dt><b>-t </b><i>char</i><dd>Use<i>char</i>as the field separator character;<i>char</i>is not considered to be part of a field(although it can be included in a sort key).Each occurrence of<i>char</i>is significant (for example,<i><char><char></i>delimits an empty field).If<b>-t</b>is not specified,blankcharacters are used as default field separators;each maximal non-empty sequence of blank characters that follows anon-blank character is a field separator.</dl><p>Sort keys can be specified using the options:<dl compact><dt><b>-k </b><i>keydef</i><dd>The<i>keydef</i>argument is a restricted sort key field definition.The format of this definition is:<pre><code><i>field_start</i><b>[</b><i>type</i><b>][</b>,<i>field_end</i><b>[</b><i>type</i><b>]]</b></code></pre>where<i>field_start</i>and<i>field_end</i>define a key field restricted to a portion of the line (seethe EXTENDED DESCRIPTION section),and<i>type</i>is a modifier from the list of charactersb,d,f,i,n,r.Thebmodifier behaves like the<b>-b</b>option, but applies only to the<i>field_start</i>or<i>field_end</i>to which it is attached.The other modifiersbehave like the corresponding options, but applyonly to the key field to which they are attached; theyhave 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>,no option applies to either.Implementations support at least nine occurrences of the<b>-k</b>option, which are significant in command line order.If no<b>-k</b>option is specified, adefault sort key of the entire line is used.When there are multiple key fields, later keysare compared only after all earlier keys compare equal.Except when the<b>-u</b>option is specified,lines that otherwise compare equal are orderedas 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) andwith all bytes in the lines significant to the comparison.The order in which lines that still compare equalare written is unspecified.<dt><i>+pos1</i><dd>Specify the start position of a key field.See the EXTENDED DESCRIPTION section.<dt><i>-pos2</i><dd>Specify the end position of a key field.See the EXTENDED DESCRIPTION section.</dl></blockquote><h4><a name = "tag_001_014_2034"> </a>OPERANDS</h4><blockquote>The following operand is supported:<dl compact><dt><i>file</i><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 "-", the standard input will be used.</dl></blockquote><h4><a name = "tag_001_014_2035"> </a>STDIN</h4><blockquote>The standard input will be used only if no<i>file</i>operands are specified,or if a<i>file</i>operand is "-".See the INPUT FILES section.</blockquote><h4><a name = "tag_001_014_2036"> </a>INPUT FILES</h4><blockquote>The input files must be text files,except that the<i>sort</i>utility will add anewline characterto the end of a file endingwith an incomplete last line.</blockquote><h4><a name = "tag_001_014_2037"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>sort</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_COLLATE</i><dd>Determine the locale for ordering rules.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single-versus multi-byte characters in arguments and input files)and the behaviour of character classification for the<b>-b</b>,<b>-d</b>,<b>-f</b>,<b>-i</b>and<b>-n</b>options.<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>LC_NUMERIC</i><dd>Determine the locale for the definition of theradix character and thousands separator for the<b>-n</b>option.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -