O'Reilly logo

Practical UNIX by Steve Moritsugu - DTR Business Systems

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sorting Files or Pipelines

Sorting means to arrange lines in alphabetical order. To sort one or more files, use the sort command, as in the following:

sort file1 file2 file3

sort will merge all the specified files into its workspace, sort the workspace, and then display the result. The sort command offers many features to enable you to control what characters or fields are used to order the lines.

Why Don’t UNIX Commands Have Built-in Sort or Paging Options?

If a user wants sorted output, or paged output, or sorted output one page at a time from any UNIX command, it is expected that the user will just pipe to sort, or pipe to pg, or pipe to sort and then to pg. In this way, UNIX utilities don’t duplicate efforts and can be more efficient.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required