Purpose: Sorts input and sends it to the screen or to a file.
SORT is a filter command (reads from input, transforms it, and outputs it
to the screen, to a file, or to a printer). SORT is used to alphabetize a
file. You can specify which column in the file to sort on. If you do not
specify a column, SORT alphabetizes using the character in the first
If you do not specify a source file, SORT can be used with input from the
keyboard or another input device.
Use the | and < redirection symbols to direct the sort output to a new
For more information about using redirection symbols, see Chapter 6, Tips for Advanced Users, in the downloadable book DOS the Easy Way.
SORT does not alphabetize upper case letters differently from lower case
Special characters (above ASCII value 127) are sorted according to
character information found in the COUNTRY.SYS file (or in a replacement
file as designated in the CONFIG.SYS file). For more information, refer
to Appendix B, Country-Specific Information.
/R - Reverses the sort (sorts from Z to A).
/+n - Starts sorting with column number (n) you enter.
To sort the file NAMES on drive A and send the output to a new file NAME2
on drive B, enter
sort < a:names > b:name2
To reverse sort (Z to A) the file PHONES.TXT on drive A and send the
output to a new file PHONE-A on drive C, enter
sort /r < a:phones.txt > b:phone-a
To create a sorted file TEMP, sorting on the character in column three,
by using input from the keyboard, enter
sort /+3 > b:temp
Then, enter lines and press the Enter key at the end of each line. When
you are finished, press and hold the Ctrl key and then press the letter Z
key. The data you enter will be sorted (based on the third character you
enter on each line) and the TEMP file will be created and stored on the
You can also pipe the output of a SORT to a file. In the following
example, the directory listing will be sorted starting with column 14 (the
column in the directory list that contains the file size). The output
will be sent to the file DIR-S on the current directory.