sort (target)

Sort all lines of text from input files (or stdin) to stdout (POSIX, toybox)

Syntax:

sort [-bcdfgiMnrsuz] [file...] [-kstart_num[,end_num[x]] [-t keysep]] [-o file...]

Runs on:

QNX OS

Options:

-b
Ignore leading blanks (or trailing blanks in second part of key).
-C
Check whether input is sorted.
-c
Warn if input is unsorted.
-d
Sort by dictionary order (use alphanumeric and whitespace characters only).
-f
Force uppercase (case insensitive sort).
-g
Sort by general numeric value (double precision with NaN and Inf).
-i
Ignore nonprinting characters.
-kstart_num[,end_num[x]
Sort by "key" (see description below).
-M
Sort by month (Jan, Feb, etc.).
-n
Sort numerically (instead of alphabetical).
-o file
Output to the specified file instead of stdout.
-r
Reverse the sort order.
-s
Skip fallback sort (only sort with keys).
-t keysep
Use a key separator other than whitespace.
-u
Sort unique lines only.
-V
Sort by version numbers (name-1.234-rc6.5b.tgz).
-x
Sort by hexadecimal numbers.
-z
Zero (NULL) terminated lines.
file
The pathname of file to sort.

Description:

The sort utility sorts all lines of text from input files (or stdin) to stdout.

The sort utility can also sort lines of text by using a key (-kstart_num[,end_num[x]) to look at a subset of words on each line. The list below are examples of its valid formats:
  • -k2 uses the second word to the end of the line
  • -k2,2 only looks at the second word
  • -k2,4 looks from the start of the second word to the end of the fourth word
  • -k2.4,5 starts from the fourth character of the second word, to the end of the fifth word.
Specifying multiple keys uses the later keys as tie breakers, in order. A type specifier appended to a sort key (such as -2,2n) applies only to sorting that key.

This utility is provided as part of the toybox package. For information on how to enable it, see toybox.

Contributing author:

Rob Landley and the toybox project (see https://landley.net/toybox/).

Page updated: