Sorting
The sort command can sort lines of text and can check
whether a file is sorted.
To specify the type of sorting you want performed, add any of the following
options:
b ignore leading blank spaces when sorting
d ignore all characters except letters, digits and
blanks when sorting
n sort according to arithmetic value of each line's
initial numeric string
r sort in reverse (descending) order
For example, to sort the words in the "wordlist" file in reverse order,
and display the sorted lines to the screen, you would enter
sort -r wordlist
[sparc03]...kaputnik>sort -r wordlist
postulate
frankfurter
exhale
dumpling
alabaster
[sparc03]...kaputnik>
To sort a file and display the sorted lines on the screen, enter
sort filename
after replacing filename with the name of the file to sort. The
results will be displayed on your screen.
[sparc03]...kaputnik>sort wordlist
alabaster
dumpling
exhale
frankfurter
postulate
[sparc03]...kaputnik>
To see if a file is in sorted order, follow the sort command with the -c option.
If the file is not sorted in ascending order, the sort command replies
that there is a disorder.
[sparc03]...kaputnik>sort -c wordlist
sort: disorder on wordlist
[sparc03]...kaputnik>
To save the sorted information to a file, include the -o output_file option,
replacing output_file with the name of the file for storing the
output.
For example, entering
sort -o sortedwords wordlist
would create a file named "sortedwords" that contains a sorted version
of the file "wordlist."
Last modified
July 20, 2004
by cawalker
|