icon Top 9 categories map      RocketAware >

sort(1)

Tips: Browse or Search all pages for efficient awareness of more than 6000 of the most popular reusable and open source applications, functions, libraries, and FAQs.


The "RKT couplings" below include links to source code, updates, additional information, advice, FAQs, and overviews.


Home

Search all pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    

RocketLink!--> Man page versions: OpenBSD FreeBSD NetBSD RedHat Solaris Others



SORT(1)                    OpenBSD Reference Manual                    SORT(1)

NAME
     sort - sort or merge text files



SYNOPSIS
     sort [-cmubdfinrH] [-t char] [-R char] [-k field1[,field2]] ... [-T dir]
          [-o output] [file] ...

DESCRIPTION
     The sort utility sorts text files by lines.  Comparisons are based on one
     or more sort keys extracted from each line of input, and are performed
     lexicographically. By default, if keys are not given, sort regards each
     input line as a single field.

     The following options are available:

     -c    Check that the single input file is sorted.  If the file is not
           sorted, sort produces the appropriate error messages and exits with
           code 1; otherwise, sort returns 0.  sort -c produces no output.

     -m    Merge only; the input files are assumed to be pre-sorted.

     -o output
           The argument given is 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 files.

     -T dir
           Use dir as the directory for temporary files.  The default is the
           contents of the environment variable TMPDIR or /var/tmp if TMPDIR
           does not exist.

     -u    Unique: suppress all but one in each set of lines having equal
           keys.  If used with the -c option, check that there are no lines
           with duplicate keys.

     The following options override the default ordering rules.  When ordering
     options appear independent of key field specifications, the requested
     field ordering rules are applied globally to all sort keys.  When at-
     tached to a specific key (see -k), the ordering options override all
     global ordering options for that key.

     -d      Only blank space and alphanumeric characters are used in making
             comparisons.

     -f      Considers all lowercase characters that have uppercase equiva-
             lents to be the same for purposes of comparison.

     -i      Ignore all non-printable characters.

     -n      An initial numeric string, consisting of optional blank space,
             optional minus sign, and zero or more digits (including decimal
             point) is sorted by arithmetic value.  (The -n option no longer
             implies the -b option.)

     -r      Reverse the sense of comparisons.

     -H      Use a merge sort instead of a radix sort.  This option should be
             used for files larger than 60Mb.

     The treatment of field separators can be altered using these options:

     -b      Ignores leading blank space when determining the start and end of
             a restricted sort key.  A -b option specified before the first -k
             option applies globally to all -k options.  Otherwise, the -b op-
             tion can be attached independently to each field argument of the
             -k option (see below).  Note that the -b option has no effect un-
             less key fields are specified.

     -t char
             char is used as the field separator character. The initial char
             is not considered to be part of a field when determining key off-
             sets (see below).  Each occurrence of char is significant (for
             example, ``charchar'' delimits an empty field).  If -t is not
             specified, blank space characters are used as default field sepa-
             rators.

     -R char
             char is used as the record separator character.  This should be
             used with discretion; -R <alphanumeric> usually produces undesir-
             able results.  The default record separator is newline.

     -k field1[,field2]
             Designates the starting position, field1, and optional ending po-
             sition, field2, of a key field.  The -k option replaces the obso-
             lescent options +pos1 and -pos2.

     The following operands are available:

     file    The pathname of a file to be sorted, merged, or checked.  If no
             file operands are specified, or if a file operand is -, the stan-
             dard input is used.

     A field is defined as a minimal sequence of characters followed by a
     field separator or a newline character.  By default, the first blank
     space of a sequence of blank spaces acts as the field separator.  All
     blank spaces in a sequence of blank spaces are considered as part of the
     next field; for example, all blank spaces at the beginning of a line are
     considered to be part of the first field.

     Fields are specified by the -k field1[,field2] argument. A missing field2
     argument defaults to the end of a line.

     The arguments field1 and field2 have the form m.n followed by one or more
     of the options -b, -d, -f, -i, -n, -r. A field1 position specified by m.n
     (m,n > 0) is interpreted as the nth character in the mth field.  A miss-
     ing .n in field1 means `.1', indicating the first character of the mth
     field; if the -b option is in effect, n is counted from the first non-
     blank character in the mth field; m.1b refers to the first non-blank
     character in the mth field.

     A field2 position specified by m.n is interpreted as the nth character
     (including separators) of the mth field.  A missing .n indicates the last
     character of the mth field; m = 0 designates the end of a line.  Thus the
     option -k v.x,w.y is synonymous with the obsolescent option +v-1.x-1
     -w-1.y; when y is omitted, -k v.x,w is synonymous with +v-1.x-1 -w+1.0.
     The obsolescent +pos1 -pos2 option is still supported, except for -w.0b,
     which has no -k equivalent.

ENVIRONMENT
     If the following environment variable exists, it is utilized by sort:

     TMPDIR      Path in which to store temporary files.  Note that TMPDIR may
                 be overridden by the -T option.

FILES
     /var/tmp/sort.*                   default temporary directories
     output#PID                        temporary name for output if output al-
                                       ready exists

SEE ALSO
     comm(1),  join(1),  uniq(1)

RETURN VALUES
     sort exits with one of the following values:

     0     Normal behavior.
     1     On disorder (or non-uniqueness) with the -c option.
     2     An error occurred.

BUGS
     Lines longer than 65522 characters are discarded and processing contin-
     ues.  To sort files larger than 60Mb, use sort -H; files larger than
     704Mb must be sorted in smaller pieces, then merged.  To protect data
     sort -o calls link and unlink, and thus fails in protected directories.

HISTORY
     A sort command appeared in Version 6 AT&T UNIX.

NOTES
     The current sort command uses lexicographic radix sorting, which requires
     that sort keys be kept in memory (as opposed to previous versions which
     used quick and merge sorts and did not).  Thus performance depends highly
     on efficient choice of sort keys, and the -b option and the field2 argu-
     ment of the -k option should be used whenever possible.  Similarly, sort
     -k1f is equivalent to sort -f and may take twice as long.

OpenBSD 2.6                      June 6, 1993                                3

Source: OpenBSD 2.6 man pages. Copyright: Portions are copyrighted by BERKELEY
SOFTWARE DESIGN, INC., The Regents of the University of California, Massachusetts
Institute of Technology, Free Software Foundation, FreeBSD Inc., and others.



(Corrections, notes, and links courtesy of RocketAware.com)


[Detailed Topics]
GNU Sources for sort(1) (at FreeBSD cvsweb)
GNU sources for sort(1) (at OpenBSD cvsweb)
OpenBSD sources for sort(1)


[Overview Topics]

Up to: Sorting Algorithms


RocketLink!--> Man page versions: OpenBSD FreeBSD NetBSD RedHat Solaris Others






Rapid-Links: Search | About | Comments | Submit Path: RocketAware > sort.1/
RocketAware.com is a service of Mib Software
Copyright 1999, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments