Options Available in Sort Command
Options |
Description |
---|---|
-o |
Specifies an output file for the sorted data. Functionally equivalent to redirecting output to a file. |
-r |
Sorts data in reverse order (descending). |
-n |
Sorts a file numerically (interprets data as numbers). |
-nr |
Sorts a file with numeric data in reverse order. Combines -n and -r options. |
-k |
Sorts a table based on a specific column number. |
-c |
Checks if the file is already sorted and reports any disorder. |
-u |
Sorts and removes duplicate lines, providing a unique sorted list. |
-M |
Sorts by month names. |
How to sort lines in text files in Linux | sort Command
SORT command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ASCII. Using options in the sort command can also be used to sort numerically.
- SORT command sorts the contents of a text file, line by line.
- sort is a standard command-line program that prints the lines of its input or concatenation of all files listed in its argument list in sorted order.
- The sort command is a command-line utility for sorting lines of text files. It supports sorting alphabetically, in reverse order, by number, by month, and can also remove duplicates.
- The sort command can also sort by items not at the beginning of the line, ignore case sensitivity, and return whether a file is sorted or not. Sorting is done based on one or more sort keys extracted from each line of input.
- By default, the entire input is taken as the sort key. Blank space is the default field separator.
The sort command follows these features as stated below:
- Lines starting with a number will appear before lines starting with a letter.
- Lines starting with a letter that appears earlier in the alphabet will appear before lines starting with a letter that appears later in the alphabet.
- Lines starting with a uppercase letter will appear before lines starting with the same letter in lowercase.
Table of Content
- Syntax of sort Command in Linux
- Options Available in Sort Command
- How to Sort Lines in Text Files in Linux Using sort Command
- How to Sort Lines in Text Files with Uppercase and Lowercase Using sort Command
- How to do Numeric Sorting in Lines in Text Files Using sort Command
- How to Sort Lines in Reverse Order in Linux File Using sort Command
- How to sort Specific Fileds in Linux Files Using sort Command
- Application and uses of sort command:
- Frequently Asked Question on Sort Command