Sort lines of text files
sort -b {ignore-leading-blanks} -d {dictionary-order} -f {ignore-case} -g {general-numeric-sort} -i {ignore-nonprinting} ๐ ignore-leading-blanks ๐ dictionary-order ๐ ignore-case ๐ general-numeric-sort ๐ ignore-nonprinting sort -b {ignore-leading-blanks} -d {dictionary-order} -f {ignore-case} -g {general-numeric-sort} -i {ignore-nonprinting} Sandbox: execFile · Timeout: 30s
system.file.sort system.file.search system.file.process system.file.copy system.file.move system.file.delete | Name | Type | Required | Default | Description | Aliases |
|---|---|---|---|---|---|
ignore-leading-blanks | string | No | - | ignore leading blanks when finding sort keys in each line | -b, --ignore-leading-blanks |
dictionary-order | integer | No | - | consider only blanks and alphanumeric characters | -d, --dictionary-order |
ignore-case | string | No | - | fold lower case to upper case characters | -f, --ignore-case |
general-numeric-sort | integer | No | - | compare according to general numerical value | -g, --general-numeric-sort |
ignore-nonprinting | string | No | - | consider only printable characters | -i, --ignore-nonprinting |
month-sort | string | No | - | compare (unknown) < 'JAN' < ... < 'DEC' | -M, --month-sort |
human-numeric-sort | string | No | - | compare human readable numbers (e.g., 2K 1G) | -h, --human-numeric-sort |
numeric-sort | integer | No | - | compare according to string numerical value; see full documentation for supported strings | -n, --numeric-sort |
random-sort | string | No | - | shuffle, but group identical keys. See also shuf(1) --random-source=FILE get random bytes from FILE | -R, --random-sort |
reverse | integer | No | - | reverse the result of comparisons --sort=WORD sort according to WORD: general-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version -V | -r, --reverse |
version-sort | string | No | - | natural sort of (version) numbers within text | -V, --version-sort |
batch-size | string | No | - | merge at most NMERGE inputs at once; for more use temp files | --batch-size |
check | string | No | - | check for sorted input; do not sort | -c, -f, --check, --check |
check-2 | string | No | - | like -c, but do not report first bad line --compress-program=PROG compress temporaries with PROG; decompress them with PROG -d --debug annotate the part of the line used to sort, and warn about que... | -C, --check, --check |
key | string | No | - | sort via a key; KEYDEF gives location and type | -k, --key |
merge | string | No | - | merge already sorted files; do not sort | -m, --merge |
output | file | No | - | write result to FILE instead of standard output | -o, --output |
stable | string | No | - | stabilize sort by disabling last-resort comparison | -s, --stable |
buffer-size | integer | No | - | use SIZE for main memory buffer | -S, --buffer-size |
field-separator | string | No | - | use SEP instead of non-blank to blank transition | -t, --field-separator |
temporary-directory | file | No | - | use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories --parallel=N change the number of sorts run concurrently to N | -T, --temporary-directory |
unique | string | No | - | output only the first of lines with equal keys; with -c, check for strict ordering | -u, --unique |
zero-terminated | string | No | - | line delimiter is NUL, not newline --help display this help and exit --version output version information and exit | -z, --zero-terminated |
compress_program | boolean | No | - | --compress-program | |
files0_from | boolean | No | - | --files0-from | |
help | boolean | No | - | --help | |
parallel | boolean | No | - | --parallel | |
random_source | boolean | No | - | --random-source | |
version | boolean | No | - | --version |
Basic usage with ignore-leading-blanks
sort ${ignore-leading-blanks} Display help message
sort --help Return the contents of the British English dictionary, in reverse order.
sort -r /usr/share/dict/british-english The GNU sort(1) command can also filter out adjacent duplicate lines and can therefore overlap with the uniq(1) command. However, uniq(1) has some options that sort(1) cannot do so refer to the man page for you situation if you require something beyond a basic uniqueness check. In addition, there is the potential for parallizing the processing by piping sort(1) into uniq(1) for non trivial tasks. By default, sort(1) sorts lines or fields using the ASCII table. Here, we're essentially getting alphanumeric sorting, where case is handled separately; - this results in these words being adjacent to one another, thus duplicates are removed. If you need better uniq-ing, you could refer to AWK & its associative arrays.
printf '%s\n' this is a list of of random words with duplicate words | sort -u Sort numerically. If you don't provide the `-n` flag, sort(1) will instead sort by the ASCII table, as mentioned above, meaning it'll display as 1, 10, - 11, 2, 3, 4, etc.
printf '%d\n' {1..9} 10 11 | sort -n You can even sort human-readable sizes. In this example, the 2nd column is being sorted, thanks to the use of the `-k` flag, and the sorting is reversed, so that the top-most storage space hungry filesystems are displayed from df(1).
df -ht ext4 /dev/sd[a-z][1-9]* | sed '1d' | sort -rhk 2 sort is a command-line utility for sort lines of text files.
sort -b {ignore-leading-blanks} -d {dictionary-order} -f {ignore-case} -g {general-numeric-sort} -i {ignore-nonprinting}