COHERENT manpages
This page displays the COHERENT manpage for sort [Sort lines of text].
List of available manpages
Index
sort -- Command Sort lines of text sort [-bcdfimnru] [-t c] [-o outfile] [-T dir] [+beg[-end]][file ...] sort reads lines from each file, or from the standard input if no file is specified. It sorts what it reads, and writes the sorted material to the standard output. sort sorts lines by comparing a key from each line. By default, the key is the entire input line (or record) and ordering is in ASCII order. The key, however, can be one or more fields within the input record; by using the appropriate options, you can select which fields are used as the key, and dictate the character that is used to separate the fields. The following options affect how the key is constructed or how the output is ordered. -b Ignore leading white space (blanks or tabs) in key comparisons. -d Dictionary ordering: use only letters, blanks, and digits when comparing keys. This is essentially the ordering used to sort telephone directories. -f Fold upper-case letters to lower case for comparison purposes. -i Ignore all characters outside of the printable ASCII range (octal 040- 0176). -n The key is a numeric string that consists of optional leading blanks and optional minus sign followed by any number of digits with an optional decimal point. Ordering is by the numeric, as opposed to alphabetic, value of the string. -r Reverse the ordering, i.e., sort from largest to smallest. As noted above, the key compared from each line need not be the entire input line. The option +beg indicates the beginning position of the key field in the input line, and the optional -end indicates that the key field ends just before the end position. If no -end is given, the key field ends at the end of the line. Each of these positional indicators has the form +m.nf or -m.nf, where m is the number of fields to skip in the input line and n is the number of characters to skip after skipping fields. Optional flags f are chosen from the above key flags (bdfinr) and are local to the specified field. The following additional options control how sort works. -c Check the input to see if it is sorted. Print the first out-of-order line found. -m Merge the input files. sort assumes each file to be sorted already. With large files, sort runs much faster with this option. -o outfile Put the output into outfile rather than on the standard output. This allows sort to work correctly if the output file is one of the input files. -tc Use the character c to separate fields rather than the default blanks and tabs. For example, -t/ uses the slash instead of white space to separate fields; this is useful when sorting file names and directory names. -T dir Create temporary files in directory dir rather than the standard place. -u Suppress multiple copies of lines with key fields that compare equally. The following example sorts the password file /etc/passwd, first by group number (field 4) and then by user name (field 1): sort -t: +3n -4 +0 -1 /etc/passwd Limits The COHERENT implementation of sort sets the following limits on input and output: Characters per input record399 Characters per output record399 Characters per field 399 Files /usr/tmp/sort* -- First attempt at temporary files /tmp/sort* -- Second attempt at temporary files See Also ASCII, commands, ctype.h, qsort(), shellsort(), tsort, uniq Diagnostics sort returns a nonzero exit status if internal problems occurred, or if the file was not correctly sorted in the case of the -c option.