To Index

 Documented in Volume 1 of the UNIX Programmers Manual.

 CAUTION: forms such as

    sort < fname > fname

   -and-

    sort fname > fname

 will destroy the file BEFORE sorting it!


 % sort -f +0.24 infile > outfile
  Sort, ignoring case, starting at field 0, (cc0), skipping 24 (start at cc25)
  of infile, storing resulting file into outfile.


 % sort +0.36 -0.40 +0.0 -0.10 xx > junk 
  Will sort file xx on columns 37-39 (major) and 1-9 (minor). The results
  will be stored into the file junk.


 % sort -u +0f +0 list
  Print in alphabetical order all the unique spellings
  in a list of words.  Capitalized words differ from uncapitalized.


 % sort -t: +2n /etc/passwd
  Print the password file ( passwd (5))
  sorted by user id number (the 3rd colon-separated field).


 % sort -um +0 -1 dates
  Print the first instance of each month in an already sorted file
  of (month day) entries.
  The options -um with just one input file make the choice of a
  unique representative from a set of equal lines predictable.


 % du -a | sort -nr | more
  starting at the current directory, list the size and name of each file
  (-a), then sort by value (-n) the initial numeric string, in descending
  sequence (-r). This is good for file housekeeping.


 % cat -n < inputfile | sort +1 -2 +0n | sed "s/^.......//"
  will maintain "stability" in the file (i.e. when keys are equal, then the
  output sequence will be identical to the input sequence). Stability is
  NOT maintained otherwise, and the output sequence of records with identical
  keys is not maintained.

To Index