sort
sort linux command cheatsheet by Thamizhiniyan C S
Introduction
sort command, as the name suggests sorts the lines alphabetically and numerically, automatically.
Syntax
sort [OPTION]... [FILE]...
Important Flags
Flags | Description |
---|---|
| Sorts in reverse order |
| This flag is used to check whether the file is already sorted or not(If not, it will list, where the disorder started) |
| To sort and removes duplicate lines(does work same as stdin redirected into |
| To save into a output file |
| Define Field Separator |
| Reorders data in a specific field |
| Sorts the file numerically |
| Sorts by month names |
Examples
Command | Description |
---|---|
Order the lines in lexicographical order | |
Order the lines in reverse lexicographical order (i.e. Z-A instead of A-Z) | |
Sort the lines in ascending order based on numbers | |
Sort the lines in descending order based on numbers | |
Sorts lines of text based on the second field (using a numerical comparison) in reverse order, considering tab characters as the field separator | |
Sort lines of text based on the second field in ascending numerical order, considering tab characters as the field separator | |
Sort lines of text based on the second field in descending numerical order, considering '|' as the field separator. |
Last updated