The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<html><head><title>sort</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
</head>
<body class='pod'>
<!--
  generated by Pod::Simple::HTML v3.01,
  using Pod::Simple::PullParser v2.02,
  under Perl v5.008002 at Thu Aug  5 13:56:21 2004 GMT.

 If you want to change this HTML document, you probably shouldn't do that
   by changing it directly.  Instead, see about changing the calling options
   to Pod::Simple::HTML, and/or subclassing Pod::Simple::HTML,
   then reconverting this document from the Pod source.
   When in doubt, email the author of Pod::Simple::HTML for advice.
   See 'perldoc Pod::Simple::HTML' for more info.

-->

<!-- start doc -->
<a name='___top' class='dummyTopAnchor' ></a>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="NAME"
>NAME</a></h1>

<p>sort - sort or sequence check text files</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="SYNOPSIS"
>SYNOPSIS</a></h1>

<p><b>sort</b> [<b>-bdfinruD</b>] [<b>-t</b> <i>str</i>|<b>-:</b> <i>regexp</i>] [<i>+pos1</i> [<i>-pos2</i>]] [<b>-k</b> <i>pos1</i>[<i>,pos2</i>]] [<i>file</i> ...]</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="DESCRIPTION"
>DESCRIPTION</a></h1>

<p>The <code lang='und' xml:lang='und'>sort</code> program sorts the lines of one or more text files.
Comparisons are based on one or more sort keys extracted from each line of input.
If no sort keys are explicitly specified,
the entire lines are used.
By default,
the comparison is made lexicographically,
using the ordering specified by the current locale (if any).</p>

<h2><a class='u' href='#___top' title='click to go to top of document'
name="Options"
>Options</a></h2>

<p>The following global options control the operation of <code lang='und' xml:lang='und'>sort</code>:</p>

<dl>
<dt><a name="-u"
><code lang='und' xml:lang='und'>-u</code></a></dt><p class="pad"></p>

<dd>Output only a single line for each set of lines having equal keys.
(&#34;unique&#34; output)</dd><p class="pad"></p>

<dt><a name="-t_STRING"
><code lang='und' xml:lang='und'>-t</code> <i>STRING</i></a></dt><p class="pad"></p>

<dd>Set the field separator to <i>STRING</i>.
The specified field separator is not included in the fields themselves.</dd><p class="pad"></p>

<dd>The space between the <b>-t</b> specifier and <i>STRING</i> is optional if and only if <i>STRING</i> consists of a single character.</dd><p class="pad"></p>

<dt><a name="-:_REGEXP"
><code lang='und' xml:lang='und'>-:</code> <i>REGEXP</i></a></dt><p class="pad"></p>

<dd>Set the field separator to <i>REGEXP</i>,
which should be a Perl regular expression.
Occurrences of / (forward slash) in <i>REGEXP</i> must be quoted.
The string matched by <i>REGEXP</i> is normally not included in the fields themselves,
but:</dd><p class="pad"></p>

<ul>
<li>If <i>REGEXP</i> contains parenthesized subexpressions,
the data matched by those subexpressions will be treated as additional fields.
(See <a href="#EXAMPLES" class="podlinkpod"
>the <i>EXAMPLES</i> section</a>.)</li><p class="pad"></p>

<li>If <i>REGEXP</i> uses lookbehind or lookahead (see <a href="http://search.cpan.org/perldoc?perlre" class="podlinkpod"
>perlre</a>),
the matched data is left as a part of the field preceding or following the match,
respectively.</li><p class="pad"></p>
</ul>

<dt><a name="-D"
><code lang='und' xml:lang='und'>-D</code></a></dt><p class="pad"></p>

<dd>Enables debugging output.
The behavior of this option is subject to change.</dd><p class="pad"></p>
</dl>

<p>The following options override the default ordering rules,
and may also be attached to specific keys (see <b>+pos1...</b> and <b>-k</b>).
When they appear independent of key field specifications,
the requested field ordering rules are applied globally to all sort keys.
When attached to a specific key,
the ordering options override all global ordering options for that key.</p>

<dl>
<dt><a name="-b"
><code lang='und' xml:lang='und'>-b</code></a></dt><p class="pad"></p>

<dd>Ignore leading whitespace when determining the start and the end of each input field.</dd><p class="pad"></p>

<dt><a name="-d"
><code lang='und' xml:lang='und'>-d</code></a></dt><p class="pad"></p>

<dd>Ignore everything except letters,
digits and whitespace characters.
(&#34;dictionary&#34; order)</dd><p class="pad"></p>

<dt><a name="-f"
><code lang='und' xml:lang='und'>-f</code></a></dt><p class="pad"></p>

<dd>Fold upper case letters to lower case.</dd><p class="pad"></p>

<dt><a name="-i"
><code lang='und' xml:lang='und'>-i</code></a></dt><p class="pad"></p>

<dd>Ignore non-printable characters.
(Requires the POSIX module to be present in the Perl installation.)</dd><p class="pad"></p>

<dt><a name="-n"
><code lang='und' xml:lang='und'>-n</code></a></dt><p class="pad"></p>

<dd>Compare fields numerically.
(An initial numeric string,
consisting of optional blanks,
optional minus sign,
and zero or more digits with optional decimal point,
is sorted by arithmetic value.)</dd><p class="pad"></p>

<dd>In some versions of <code lang='und' xml:lang='und'>sort</code>,
<b>-n</b> implies <b>-b</b> (which matters if you use character position offsets).
With this version,
if you want <b>-b</b>,
use <b>-b</b>.</dd><p class="pad"></p>

<dt><a name="-r"
><code lang='und' xml:lang='und'>-r</code></a></dt><p class="pad"></p>

<dd>Reverse the sense of comparisons (and therefore the order of sorting).</dd><p class="pad"></p>
</dl>

<p>Finally,
there are two,
mutually confusing,
ways of specifying sort keys:</p>

<dl>
<dt><a name="+POS1_[-POS2]"
><i>+POS1</i> [<i>-POS2</i>]</a></dt><p class="pad"></p>

<dd>Specifies the starting position,
<i>POS1</i>,
and optionally the ending position,
<i>POS2</i>,
of a sort key.
<i>POS2</i> denotes the first position <b>not</b> to be included in the sort key.
A missing <i>POS2</i> argument indicates that the key should include all fields until the end of the line.</dd><p class="pad"></p>

<dd>Each of <i>POS1</i> and <i>POS2</i> is of the form <i>M</i>[.<i>N</i>],
followed by zero or more of the option letters <b>b</b>,
<b>d</b>,
<b>f</b>,
<b>i</b>,
<b>n</b> and <b>r</b>.
<i>M</i> is a non-negative integer specifying the field.
If present,
<i>N</i> is a non-negative integer specifying the character offset into the <i>M</i>th field.
Both <i>M</i> and <i>N</i> are <b>counted from 0</b>; thus,
<code lang='und' xml:lang='und'>1.2</code> specifies the third character of the second field.
If .<i>N</i> is omitted,
the position refers to the start of the field,
so <code lang='und' xml:lang='und'>2</code> is equivalent to <code lang='und' xml:lang='und'>2.0</code>.</dd><p class="pad"></p>

<dd>The option letters,
if present,
specify options to be used for the current sort key; if no letters are specified,
the global sort options are used.</dd><p class="pad"></p>

<dd>The <i>-POS2</i> argument must immediately follow the <i>+POS1</i> argument.
Things like <code lang='und' xml:lang='und'>sort +1 -n -2</code> will produce an error.</dd><p class="pad"></p>

<dt><a name="-k_POS1[,POS2]"
><code lang='und' xml:lang='und'>-k</code> <i>POS1</i>[<i>,POS2</i>]</a></dt><p class="pad"></p>

<dd>Specifies the starting position,
<i>POS1</i>,
and optionally the ending position,
<i>POS2</i>,
of a sort key.
<i>POS2</i> denotes the <b>last</b> position to be included in the sort key.
A missing <i>POS2</i> argument indicates that the key should include all fields until the end of the line.</dd><p class="pad"></p>

<dd>Each of <i>POS1</i> and <i>POS2</i> is of the form <i>M</i>[.<i>N</i>],
followed by zero or more of the option letters <b>b</b>,
<b>d</b>,
<b>f</b>,
<b>i</b>,
<b>n</b> and <b>r</b>.
<i>M</i> is a non-negative integer specifying the field.
If present,
<i>N</i> is a non-negative integer specifying the character offset into the <i>M</i>th field.
Both <i>M</i> and <i>N</i> are <b>counted from 1</b>; thus,
<code lang='und' xml:lang='und'>1.2</code> specifies the second character of the first field.
If the character offset of <i>POS1</i> is omitted,
the position refers to the start of the field,
so <code lang='und' xml:lang='und'>-k 2,...</code> is equivalent to <code lang='und' xml:lang='und'>-k 2.1,...</code> .
If the character offset of <i>POS2</i> is omitted,
the position refers to the <b>end</b> of the field.</dd><p class="pad"></p>

<dd>As a special case,
if the character offset of <i>POS2</i> is zero,
it is taken to refer to the <b>end</b> of the specified field,
just as if it was omitted.
Thus,
<code lang='und' xml:lang='und'>-k ...,2</code> is equivalent to <code lang='und' xml:lang='und'>-k ...,2.0</code> .</dd><p class="pad"></p>

<dd>The option letters,
if present,
specify options to be used for the current sort key; if no letters are specified,
the global sort options are used.</dd><p class="pad"></p>
</dl>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="EXAMPLES"
>EXAMPLES</a></h1>

<pre lang='und' xml:lang='und'>        sort +1 -2
        sort -k 2,2
Either example sorts lexicographically by the second field of each line.

        sort +1 -2 +3 -5
        sort -k 2,2 -k 4,5
        sort +1 -2 -k 4,5
Sorts lexicographically by the second, fourth and fifth field of each
line.  (More verbosely, to compare two lines, we first compare their
second field.  If the two second fields are lexicographically equal,
we compare the fourth field.  If the fourth fields are equal, compare
the fifth field.  If the fifth fields are also equal, the lines are
considered equal.)

        sort -n +2 +0b -1
        sort -n -k 3 -k 1b,1
Sorts numerically by the fields of each line starting from the third
(ie, 3rd, 4th, 5th, ...).  If two lines compare as equal, compare the
first field lexicographically, ignoring any leading whitespace.

        sort -n +2.1 -2.4
        sort -n -k 3.2,3.4
Numerically compares the second through fourth characters of the third
field.

        sort.pl -t: +2n /etc/passwd
Splits the lines of the file C&#60;/etc/passwd&#62; into colon-separated
fields, and sorts numerically on fields starting from the third field.

        sort -: &#39;(\d+)&#39; +3n -4 +2 -3 +1n -2
Separates the input into fields consisting alternately of either all
non-digits or all digits.  (The regular expression instructs C&#60;sort&#62;
to use fields separated by fields of digits.  Therefore, the first
field will be non-digits, but may be empty.)  Sort numerically by
the fourth field (second numeric field), lexicographically by the
third field (second non-numeric field), and numerically by the second
field (first numeric field).</pre>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="ENVIRONMENT"
>ENVIRONMENT</a></h1>

<p>These environment variables affect the execution of <code lang='und' xml:lang='und'>sort</code>:</p>

<dl>
<dt><a name="LC_COLLATE"
>LC_COLLATE</a></dt><p class="pad"></p>

<dd>Determine the locale for ordering rules.</dd><p class="pad"></p>

<dt><a name="LC_CTYPE"
>LC_CTYPE</a></dt><p class="pad"></p>

<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (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.</dd><p class="pad"></p>
</dl>

<p>See <a href="http://search.cpan.org/perldoc?locale" class="podlinkpod"
>locale</a> for more information about localization and Perl.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="BUGS"
>BUGS</a></h1>

<p>No bugs in <code lang='und' xml:lang='und'>sort</code> are currently known.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="AUTHOR"
>AUTHOR</a></h1>

<p>Albert Dvornik, &#60;bert@mit.edu&#62;.</p>

<h1><a class='u' href='#___top' title='click to go to top of document'
name="COPYRIGHT_and_LICENSE"
>COPYRIGHT and LICENSE</a></h1>

<p>This program is copyright (c) Albert Dvornik 1999.</p>

<p>This program is free and open software. You may use, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same.</p>

<!-- end doc -->

</body></html>