Next 14.F: Compare: diff, comp Up 14: File Utilities Prev 14.F: Find Files Contents


Specialized

§ 14.H: Sorting Files with sort


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

This sorts the file into alphabetic order, moving from left to right across the line.

Now use more or view to+see the changes.

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

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

Now remove the large file 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.


Next 14.F: Compare: diff, comp Up 14: File Utilities Prev 14.F: Find Files Contents


Comments and questions to CP-unix@physics.orst.edu.