What are other common sort options?

Here are some other common options for the sort command:

  1. -b: Ignore leading blanks when sorting.

    sort -b input_file.txt
  2. -f: Ignore case when sorting (case-insensitive sort).

    sort -f input_file.txt
  3. -c: Check if the input is already sorted. It will not produce output but will return an exit status.

    sort -c input_file.txt
  4. -u: Suppress duplicate lines, only outputting unique lines.

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

    sort -o sorted_output.txt input_file.txt
  6. -m: Merge already sorted files. This option assumes that the input files are already sorted.

    sort -m file1.txt file2.txt
  7. -V: Sort version numbers (e.g., 1.2, 1.10, 2.0).

    sort -V input_file.txt
  8. -S SIZE: Specify the amount of memory to use for sorting. For example, -S 50% uses 50% of available memory.

    sort -S 50% input_file.txt
  9. --reverse: An alternative to -r, this option also sorts in reverse order.

    sort --reverse input_file.txt
  10. --key=KEYDEF: An alternative way to specify sorting keys, similar to -k.

    sort --key=2,2 input_file.txt

These options can be combined to customize the sorting behavior according to your needs. For example, you can sort numerically while ignoring case and suppressing duplicates:

sort -n -f -u input_file.txt

0 Comments

no data
Be the first to share your comment!