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.

SORT Syntax:

Terminal window
sort [option] [file]

Options:

OptionDescription
/?Displays help at the command prompt.
/+nSkips the first ‘n-1’ fields before sorting.
/RReverses the sort order (descending).

Parameters:

ParameterDescription
fileSpecifies the file to be sorted.

SORT Command Samples:

Sort a File Alphabetically

Terminal window
sort input.txt

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

Sort a File Numerically

Terminal window
sort /n input.txt

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

Sort File in Reverse Order

Terminal window
sort /r input.txt

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

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.

Sort and Output to a New File

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.”

Case-Insensitive Sorting

Terminal window
sort /i input.txt

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

Sort a File with Custom Delimiter

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.

SORT FAQ:

How do I use sort in Windows?

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?

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?

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?

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?

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?

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

Applications of the SORT Command

  • 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