Here are some commonly used options for the sort command:
-
-r: Sort in reverse order (descending).sort -r file.txt -
-n: Sort numerically instead of lexicographically.sort -n file.txt -
-k: Specify a key (field) to sort by. You can define the starting and ending fields.sort -k2,2 file.txt # Sort by the second field -
-u: Output only the first of an equal run (remove duplicates).sort -u file.txt -
-o: Write the output to a specified file instead of standard output.sort -o sorted.txt file.txt -
-f: Ignore case when sorting.sort -f file.txt -
-b: Ignore leading blanks when sorting.sort -b file.txt -
-t: Specify a custom delimiter (as mentioned earlier).sort -t, -k1,1 file.csv -
-M: Sort by month name.sort -M file.txt
These options can be combined to achieve more complex sorting behaviors. For example, you can sort numerically in reverse order while ignoring case and specifying a custom delimiter.
