Previous Section  < Day Day Up >  Next Section

sort—sorts and/or merges files


sort [ –cmu ] [ –ooutput ] [ –T directory ] [ –ykmem ]

   [ –dfiMnr ] [ –btx ] [ +pos1 [ –pos2 ]] [ filename...]


The sort command sorts (ASCII) lines of all the named files together and writes the result on the standard output. Comparisons are based on one or more sort keys extracted from each line of input. By default, there is one sort key, the entire input line, and ordering is lexicographic by bytes in machine collating sequence.

Example A.51.

1   sort filename

2   sort -u filename

3   sort -r filename

4   sort +1 -2 filename

5   sort -2n filename

6   sort -t: +2n -3 filename

7   sort -f filename

8   sort -b +1 filename


EXPLANATION

  1. Sorts the lines alphabetically.

  2. Sorts out duplicate entries.

  3. Sorts in reverse.

  4. Sorts starting on field 1 (fields are separated by whitespace and start at field 0), stopping at field 2 rather than sorting to the end of the line.

  5. Sorts the third field numerically.

  6. Sorts numerically starting at field 2 and stopping at field 3, with the colon designated as the field separator (–t:).

  7. Sorts folding in uppercase and lowercase letters.

  8. Sorts starting at field 1, removing leading blanks.

    Previous Section  < Day Day Up >  Next Section