What are other sort command options?

086

Here are some commonly used options for the sort command:

  1. -r: Sort in reverse order (descending).

    sort -r file.txt
  2. -n: Sort numerically instead of lexicographically.

    sort -n file.txt
  3. -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
  4. -u: Output only the first of an equal run (remove duplicates).

    sort -u file.txt
  5. -o: Write the output to a specified file instead of standard output.

    sort -o sorted.txt file.txt
  6. -f: Ignore case when sorting.

    sort -f file.txt
  7. -b: Ignore leading blanks when sorting.

    sort -b file.txt
  8. -t: Specify a custom delimiter (as mentioned earlier).

    sort -t, -k1,1 file.csv
  9. -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.

0 Comments

no data
Be the first to share your comment!