14.F: Compare: diff, comp | 14: File Utilities | 14.F: Find Files |
The sort command can be used to sort one or more files together or to eliminate duplicate lines. The most basic use gives the command followed by the filename
> sort sample.doc > sample.sort
This sorts the file into alphabetic order, moving from left to right across the line.
Now use more or view to+see the changes.
> more sample.sort
Notice that all of the blank lines have been moved to the top of the file, which means that the first page you see is (probably) blank.
A useful option with sort is -u to eliminate duplicate lines
> sort -u bugs.dat > bugs.sort
This can substantially decrease the size of the file and the time it takes to print it out.
Use the list command to see how much smaller this file is
> ls -l bugs.*
Now remove the large file bugs.dat.
> rm bugs.dat
As expected, sort has options to define fields or columns to be sorted and types of sorts to be made. Read about some of them in Coping with Unix, or about all of them in the man pages.
14.F: Compare: diff, comp | 14: File Utilities | 14.F: Find Files |