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.
For example, to sort the file data.txt, the command would be
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
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