Skip to content

SORT Windows Command Guide

The Windows sort command is used to alphabetically sort the contents of a text file and display the results in the Command Prompt window. This command is helpful for organizing data in a specific order based on characters or numbers. By default, the sort command arranges the text in ascending order, but you can also specify options to customize the sorting process.

Terminal window
sort [option] [file]
OptionDescription
/?Displays help at the command prompt.
/+nSkips the first ‘n-1’ fields before sorting.
/RReverses the sort order (descending).
ParameterDescription
fileSpecifies the file to be sorted.
Terminal window
sort input.txt

This command sorts the lines in the file “input.txt” in alphabetical order.

Terminal window
sort /n input.txt

Sorts the lines in the file “input.txt” numerically.

Terminal window
sort /r input.txt

Arranges the lines in the file “input.txt” in reverse order.

Sort Multiple Files and Display Unique Lines

Section titled “Sort Multiple Files and Display Unique Lines”
Terminal window
sort /u file1.txt file2.txt

Combines and sorts the contents of “file1.txt” and “file2.txt,” displaying only unique lines.

Terminal window
sort input.txt > sorted_output.txt

Sorts the lines in “input.txt” and saves the sorted output to a new file named “sorted_output.txt.”

Terminal window
sort /i input.txt

Sorts the content in “input.txt” while ignoring differences in case sensitivity.

Terminal window
sort /t"," /+2 input.csv

Sorts the lines in a CSV file “input.csv” using a comma as the delimiter and starting from the third column.

To use the sort command in Windows, execute the following command:

Terminal window
sort <filename>

How can I sort a file in reverse order in Windows?

Section titled “How can I sort a file in reverse order in Windows?”

To sort a file in reverse order using the sort command in Windows, you can use the /r option. Here’s an example:

Terminal window
sort /r <filename>

What is the command to sort a file and remove duplicate lines in Windows?

Section titled “What is the command to sort a file and remove duplicate lines in Windows?”

To sort a file and remove duplicate lines using the sort command in Windows, you can use the /unique option. Here’s an example:

Terminal window
sort /unique <filename>

How can I sort a file numerically in Windows?

Section titled “How can I sort a file numerically in Windows?”

To sort a file numerically using the sort command in Windows, you can use the /n option. Here’s an example:

Terminal window
sort /n <filename>

How do I ignore leading blanks when sorting in Windows?

Section titled “How do I ignore leading blanks when sorting in Windows?”

To ignore leading blanks when sorting in Windows using the sort command, you can use the /+<n> option where <n> is the number of characters to ignore. Here’s an example:

Terminal window
sort /+2 <filename>

Can I sort multiple files at once in Windows using the sort command?

Section titled “Can I sort multiple files at once in Windows using the sort command?”

Yes, you can sort multiple files at once in Windows using the sort command by specifying the filenames separated by spaces. Here’s an example:

Terminal window
sort file1.txt file2.txt
  • Arrange data in alphabetical order
  • Sort data in descending order
  • Remove duplicates from a list
  • Organize data in numerical order
  • Merge and sort multiple files
  • Customize sorting criteria with different options