Hamilton LaboratoriesHamilton C shell 2012User guideExternal utilities

sort

Oregon Coast

sort
Previous | Next

        Sort and/or Merge Files

Usage:  hsort [-cmh] [-o output] [-RsuvdfinxNXWrb] [-tT char]
              [-k keydef] ... [+pos1 [-pos2]] ... [file ...]

   Sort or merge lines of text from the named files or from
   stdin if no file specification is given.  Comparisons are
   based on one or more sort keys extracted from each line.
   By default, there is one sort key, the entire line (minus
   any line termination characters), and ordering is done
   according to the ASCII collate sequence.

Options:

   -c         Check that the input is ordered as specified.  No
              output is produced.  Only the exit code is affected.
   -m         Merge only.  The input files are assumed to be
              already sorted.
   -o output  Write the output to file specified.  This can be the
              same as one of the input files.
   -R         Ensure that each record ends with a \r\n sequence.
   -s         Stable sort.  If records match on all the sort keys,
              preserve the input ordering.
   -u         Unique:  suppress all but one in each set of lines
              having equal keys.  If used with -c, check that
              there are no lines with equal keys.
   -v         Verbose.  If the input is checked with -c and it's
              out of order, print the record number and contents.

Comparison Options:

   The following options override default ordering rules.  When
   these options appear independent of any key field specifi-
   cation, they apply globally to all sort keys.  When attached
   to a specific key, they override any global ordering options.

   -d         Only blanks and alphanumeric characters are
              considered in comparing keys.  
   -f         Case-independent comparison:  upper and lower case
              characters will compare equal.
   -i         Ignore any non-printable characters.
   -n         Interpret the field as decimal integer data which
              may contain optional leading spaces, plus or
              minus sign, and commas as thousands separators.
   -x         Like -n, but also accepts octal or hex integers.
   -N         Like -n, but also accepts floating point data
              containing fractional components or exponents
              expressed in E-notation, e.g., 1.0E-03 to mean
              .001.
   -X         Like -N, but also accepts octal or hex integers.
   -W         Use the Win32 CompareString function to compare
              strings according to the collate sequence specified
              by the user's locale descriptor.  Otherwise, by
              default, the standard ASCII collate sequence is
              used for much greater performance.
   -r         Reverse the sense of comparisons.

Field Separator Options:

   -b         Ignore leading or trailing spaces when determining
              the starting and ending positions of a sort key.
   -t char    Use <char> as the field separator character; <char>
              is not considered to be part of a field.  Each
              occurrence of <char> is significant so, e.g.,
              <char><char> delimits an empty field.
   -T char    Like -t, but each maximal sequence of <char>
              characters is considered a single field separator.
              By default, each maximal sequence of spaces is a
              field separator.

Sort Key Specification:

   -k keydef  Define a sort key field.  The format of <keydef> is

                 field_start[type][,field_end[type]]

              where <field_start> and <field_end> define the
              beginning and ending points of a field as:

                 field_number[.first_character]

              where both fields and characters are numbered
              starting from 1 and specified as positive decimal
              integers. If <.first_character> is omitted from
              a <field_start>, the sort key begins with the
              first character of the field; if it's omitted
              from a <field_end>, the key ends with the last
              character of the field.

              As a special case, a field number of 0 specifies
              the entire record.  A character number of 0
              specifies the last character of the field.

              The <type> modifiers can be any combination of
              b, d, f, i, n, N or r, which behave just like the
              corresponding options, except as a modifier
              they affect only the specified sort key.  The
              b modifier applies only to the <field_start> or
              <field_end> to which it is attached.

              If the -b option or b type modifier is specified,
              characters within the field are counted from the
              first non-blank character.

              When there are multiple key fields, later keys
              are compared only after all earlier keys compare
              equally.  Except when -u is specified, lines that
              otherwise compare equally are ordered as if no
              -d, -f, -i, -n, -N or -k options were present and
              with all bytes in the lines significant to the
              comparison.

   +pos1 [-pos2]  An older form of key field specification, now
              considered obsolete by POSIX.  The <pos1> and
              <pos2> entries specify the start and end of a key
              just the way the -k option would except that in
              this form, fields and characters are numbered
              starting at 0, not 1.  A fully-specified key of
              the form +pos1 -pos2 with type modifiers T and U:

                     +w.xT -y.zU

              is equivalent to:

                     -k (w+1).(x+1)T,y.0U        (z == 0)
                     -k (w+1).(x+1)T,(y+1).zU    (z > 0)

   -h         Help (short list.)
   --         End of options.

Exit status:

   0          All the input was sorted successfully, or -c was
              specified and the input was already sorted.
   1          The -c option was specified and the input was not
              ordered correctly or -cu was specified and two
              lines sorted equal.
   >1         An error occurred.

Previous | Next