The SORT command is used to read ASCII text input and to sort the lines in alphanumeric order.
To sort a text file:
SORT [/R] [/+n] filename
SORT [/R] [/+n] < filename
To sort the output of a Dos command:
command | SORT [/R] [/+n]
To sort keyboard input:
SORT [/R] [/+n] [> outputfile]
keyboard input first line
keyboard input last line
|/R||Reverses the sort order; that is, sorts Z to A, then 9 to 0.|
|/+n||Sorts the file according to characters in column n.|
- The input to SORT should be ASCII text structured so that each line can be considered a record of data. The lines (records) may be broken into fields, each beginning a fixed number of characters from the start of the line (eg. the output from a DIR command). Input in any other form tends to produce nonsense after being sorted (eg the output from a "readme.txt" file).
- SORT can handle files up to 64K and is not case sensitive
- The output from SORT is, by default, sent to the "Standard Output Device" (usually the screen), but can be redirected to any other device or a file using the redirection symbol (>).
- The SORT program uses the collating-sequence table corresponding to the country code and code-page settings. Characters greater than ASCII code 127 are sorted based on information in the COUNTRY.SYS file or in an alternate file specified by the COUNTRY command in your CONFIG.SYS file.
- The Dos 7 version of SORT does appear to have a bit of a problem when handling very long lines. When sorting such lines, under certain conditions, some lines break up. An example of this anomalous behavior has been reported in which one line of three split when sorted on the 14th character. There were no problems when the sort was based on the first, 16th or 48th characters. Apparently the maximum "safe" line length is 510 characters/columns.
- To search a file named MailingList.txt for the text "Jones", and then sort the results of the search, use the pipe ( | ) to direct the output of a FIND command to the SORT command:
FIND /I "Jones" MailingList.txt | SORT
- If there are too many entries to fit on a screen, add the MORE command:
FIND /I "Jones" MailingList.txt | SORT | MORE
|File Name||Default Location||Dos Ver.||Win Ver.||Size||Date||Source|
Superscripts denote which same size files, if any, are identical (using FC).