next up previous contents
Next: Counting Words - wc Up: Miscellaneous Previous: Removing Doubled Up Lines

Sorting Lines - sort

 

There is an all-purpose sorting utility on UNIX called sort. It has quite a few options, one of which is the ``-u'' (unique) which removes the need to pipe the output of sort into the uniq program.

You can sort files in alphabetical, numerical or phone directory orders, you can reverse the sense of the sort, you can sort on one (or more) fields, with the field definition left to the user, ignore case, etcetera.

For example, you might want to sort the password file (/etc/passwd) based on what login shell each user had. We will note that the fields in this file are separated by colons.

 sort -t: +6 /etc/passwd


next up previous contents
Next: Counting Words - wc Up: Miscellaneous Previous: Removing Doubled Up Lines

Gordon Haverland
Sat Oct 9 13:50:48 MDT 1999