sort : sort lines of text files
[SYNOPSIS] sort OPTION FILE
OPTION
-b ignore leading blanks
-d consider only blanks and alphanumeric characters
-f fold lower case to upper case characters
-g compare according to general numerical value
-i consider only printable characters
-M compare (unknown) < 'JAN' < ... < 'DEC'
-h compare human readable numbers (e.g., 2K 1G)
-n compare according to string numerical value
-R shuffle, but group identical keys. See shuf(1)
-r reverse the result of comparisons
-V natural sort of (version) numbers within text
-c check for sorted input; do not sort
-k KEYDEF sort via a key; KEYDEF gives location and type
KEYDEF ⇒ F[.C][OPTS][,F[.C][OPTS]]
F : field number
C : character position in the field
OPTS : [bdfgiMhnRrV] - one or more single-letter ordering options
-m merge already sorted files; do not sort
-o FILE write result to FILE instead of standard output
-S SIZE use SIZE for main memory buffer
-t SEP use SEP instead of non-blank to blank transition
-T DIR use DIR for temporaries, not $TMPDIR or /tmp
multiple options specify multiple directories
-u with -c, check for strict ordering
without -c, output only the first of an equal run
-z with -c, check for strict ordering
without -c, output only the first of an equal run
Usage example :
[root@localhost ~]# cat test.txt
Tokyo:February 01
Hiroshima:December 005
Osaka:November 003
hokkaido:July 002
kyoto:August 04

[root@localhost ~]# sort test.txt
Hiroshima:December 005
hokkaido:July 002
kyoto:August 04
Osaka:November 003
Tokyo:February 01

[root@localhost ~]# sort -k2 test.txt
hokkaido:July 002
Osaka:November 003
Hiroshima:December 005
Tokyo:February 01
kyoto:August 04

[root@localhost ~]# sort -k2 -g test.txt
Tokyo:February 01
hokkaido:July 002
Osaka:November 003
kyoto:August 04
Hiroshima:December 005

[root@localhost ~]# sort -t':' -k2 test.txt
kyoto:August 04
Hiroshima:December 005
Tokyo:February 01
hokkaido:July 002
Osaka:November 003

[root@localhost ~]# sort -t':' -k2M test.txt
Tokyo:February 01
hokkaido:July 002
kyoto:August 04
Osaka:November 003
Hiroshima:December 005