Reads input, sorts data, and writes the results to the screen, a file, or another device.
SORT acts as a filter, reading characters in a specified column and rearranging them in ascending or descending order.
SORT [/L[OCALE] locale] [/M[EMORY] kilobytes] [/O[UTPUT] [drive:][pathname]] [/R] [/REC[ORD_MAXIMUM] characters] [/T[EMPORARY] [drive:][path]] [/+n] [<] [[drive1:][path1]filename1] [> [drive2:][path2]filename2]
[command |] SORT [/L[OCALE] locale] [/M[EMORY] kilobytes] [/O[UTPUT] [drive:][pathname]] [/R] [/REC[ORD_MAXIMUM] characters] [/T[EMPORARY] [drive:][path]] [/+n] [> [drive2:][path2]filename2]
For information about displaying information one screen at a
time, see the MORE command.
TYPE - Display the contents of a text file.
Redirection - Redirect files, command output and error messages.
Equivalent Linux BASH commands:
sort - Sort text files.
Unless you specify the command or filename parameter, SORT acts as a filter and takes input from the operating system standard input (usually from the keyboard, from a pipe, or from a file).
You can use the pipe (|) or the less-than sign (<) to direct data through the SORT command from command or filename. If you want to display the information one screen at a time or direct the information to a file, you can also specify the MORE command or a filename. You can use the greater-than sign (>) to direct the sorted output to a file.
Before using a pipe for redirection, you should set the TEMP environment variable in your AUTOEXEC.BAT file.
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.
SORT does not distinguish between uppercase and lowercase letters.
The SORT command can handle files as large as 64K.
The SORT command has problems with lines longer than 510 characters.
This command reads the file EXPENSES.TXT, sorts it in reverse order, and displays it on your screen:
SORT /R < EXPENSES.TXT
Suppose you want to search a large file named MAILLST.TXT for the text "Jones", and suppose you want to sort the results of the search. To do this, use the pipe (|) to direct the output of a FIND command to the SORT command, as shown in the example:
FIND "jones" MAILLST.TXT | SORT
The command produces a sorted list of lines that contain the specified text.
To sort keyboard input and display the results alphabetically on the screen, you can first use the SORT command with no parameters, as the example shows:
Then type the text you want sorted, pressing ENTER at the end of each line. When you have finished typing text, press CTRL+Z (^Z), and then press ENTER. The SORT command displays the text you typed, sorted alphabetically. You could also redirect sorted keyboard input to a file.