sort
sort is a standard Unix command line program that prints the lines of its input or concatenation of all files listed in its argument list in sorted order. Sorting is done based on one or more sort keys extracted from each line of input.[1]
- GNU Coreutils [EN] @ Fedora Package
- GNU Coreutils [EN] @ Homebrew Formula
Documentation
- sort [EN] @ GNU Coreutils Manual
- man 1 'sort' [EN]
Parameters
- -f, --ignore-case
- Fold lower case to upper case characters.
- -h, --human-numeric-sort
- Compare human readable numbers (e.g. 2K, 1G).
- -k POS1[,POS2], --key=POS1[,POS2]
- Start a key at POS1 (origin 1), end it at POS2 (default end of line).
- -n, --numeric-sort
- Compare according to string numerical value.
- -r, --reverse
- Reverse the result of comparisons.
- --random-source=FILE
- Get random bytes from FILE (e.g. /dev/random or /dev/urandom).
- -R, --random-sort
- Sort by random hash of keys.
- -V, --version-sort
- Natural sort of (version) numbers within text.
Examples
- Sort a comma separated string ignoring the first char
sed 's/\n//g; s/, */\n/g' <<<'.foo, #bar, -bla' \
| sort --key='1.2' \
| awk '{printf("%s%s", sep, $0); sep=", "} END {print ""}'
Output:
#bar, -bla, .foo