Sorting text files (sort command)
Use the sort command to alphabetize lines in the files specified by the File parameters and write the result to standard output.
If the File parameter specifies more than one file, the
sort command concatenates the files and alphabetizes them as one file.
Note: The
sort command is case-sensitive and orders uppercase letters before lowercase
(this behavior is dependent on the locale).
In the following examples, the contents of the
file named names
are:
marta
denise
joyce
endrica
melanieand the contents of the file named
states are:texas
colorado
ohio- To display the sorted contents of the file named names, type the following:
The system displays information similar to the following:sort namesdenise endrica joyce marta melanie - To display the sorted contents of the names and states
files, type the following:
The system displays information similar to the following:sort names statescolorado denise endrica joyce marta melanie ohio texas - To replace the original contents of the file named names with its sorted
contents, type the following:
This replaces the contents of the names file with the same data but in sorted order.sort -o names names
See the sort command in the Commands Reference, Volume 5 for the complete syntax.