Sorting Files with sort

If you want to be reallylazy—er, um, smart— let Unix sort files for you. You can use sort to, for example, sort your address book alphabetically—as opposed to the random order in which you might have entered addresses (see Code Listing 6.17).

To Sort Files with sort:

  • sort address.book >
    >sorted.address.book

    To begin, type sort, followed by the name of the file you want to sort. Unix will sort the lines in the file alphabetically and present the sorted results in the file you specify (here, sorted.address.book), as shown in Code Listing 6.17.

Code Listing 6.17. An unsorted address book springs to order with the help of sort.
[ejr@hobbes manipulate]$ more address.book Schmidt, Sven, 1 Circle Drive, Denver, CO, 80221, 555-555-8382 ...

Get Unix Third Edition: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.