Sort command

by admin on December 26, 2011

We can sort a text file using the windows inbuilt sort command. Below you can find the syntax of sort command.

Sort a text file:

A text file can be sorted using the below simple command.

sort filename

For example, to sort the file data.txt, the command would be
sort data.txt

The above command prints the sorted contents of the file in the console. To save the output into another file, you can use
/o switch as shown below.

sort filename /o outputfile

Example:

sort data.txt /o sorteddata.txt

Alternatively, you can user redirection operator.

sort data.txt > sorteddata.txt

Advanced options for sorting:

Sort the contents in reverse order

sort /R filename /o outputfile

If you are sorting big files, then /M switch will help you to finish the sorting quickly. Be default, sort command uses only 160 KB of space to store the file contents in main memory. Increasing this limit, will increase the performance of the sort operation. To let the sort command use 10MB of memory, we can run the below command.

sort /M 10240 data.txt /o sorteddata.txt

{ 0 comments… add one now }

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: