You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.5 KiB
Plaintext

# sort
# Sort lines of text files
# 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