Sort


Applies To: Windows Server 2008 R2,Windows Server 2008,Windows Server 2003 with SP1,Windows Server 2000,Windows Server 2003 with SP2,Windows Server 2003,Windows Vista,Windows Server 2003 R2

Reads input, sorts data, and writes the results to the screen, to a file, or to another device.

For examples of how to use this command, see Examples.

Syntax


Copy Code

sort [/r] [/+<N>] [/m <Kilobytes>] [/l <Locale>] [/rec <Characters>] [[<Drive1>:][<Path1>]<FileName1>] [/t [<Drive2>:][<Path2>]] [/o [<Drive3>:][<Path3>]<FileName3>]

Parameters

Parameter

Description

/r

Reverses the sort order (that is, sorts from Z to A and from 9 to 0).

/+<N>

Specifies the character position number where sort will begin each comparison. N can be any valid integer.

/m <Kilobytes>

Specifies the amount of main memory to use for the sort in kilobytes (KB).

/l <Locale>

Overrides the sort order of characters that are defined by the system default locale (that is, the language and Country/Region selected during installation).

/rec <Characters>

Specifies the maximum number of characters in a record or a line of the input file (the default value is 4,096 and the maximum is 65,535).

[<Drive1>:][<Path1>]<FileName1>

Specifies the file to be sorted. If no file name is specified, the standard input is sorted. Specifying the input file is faster than redirecting the same file as standard input.

/t [<Drive2>:][<Path2>]

Specifies the path of the directory to hold the sort command's working storage if the data does not fit in the main memory. By default, the system temporary directory is used.

/o [<Drive3>:][<Path3>]<FileName3>

Specifies the file where the sorted input is to be stored. If not specified, the data is written to the standard output. Specifying the output file is faster than redirecting standard output to the same file.

/?

Displays help at the command prompt.

Remarks

Examples

Sorting a file

To sort and display in reverse order the lines in a file named Expenses.txt, type:

sort /r expenses.txt

Sorting the output from a command

To search a large file named Maillist.txt for the text "Jones," and to sort the results of the search, use the pipe (|) to direct the output of a find command to the sort command, as follows:

find "Jones" maillist.txt | sort

The command produces a sorted list of lines that contain the specified text.

Sorting keyboard input

To sort keyboard input and display the results alphabetically on the screen, you can first use the sort command with no parameters, as follows:

sort

Then type the text that you want sorted, and press ENTER at the end of each line. When you have finished typing text, press CTRL+Z, and then press ENTER. The sort command displays the text you typed, sorted alphabetically.

Additional references

Command-Line Syntax Key