How are the following sorting commands in unix different?
1) sort -k1,4 < file 2) sort -k1,1 -k4,4 < file 3) sort -k1,1 -k2,2 -k3,3 -k4,4 < file
In particular, # 1 and # 2 are confusing. For example, the following example illustrates my points
$ cat tmp 1 2 3 t 4 2 4 c 5 4 6 c 7 3 20 r 12 3 5 i 2 45 7 a 11 23 53 b 23 43 53 q 11 6 3 c 0 4 3 z $ diff <(sort -k1,4 tmp) <(sort -k1,1 -k2,2 -k3,3 -k4,4 tmp) 1a2 > 1 2 3 t 5,6d5 < 1 2 3 t < 23 43 53 q 7a7 > 23 43 53 q $diff <(sort -k1,4 tmp) <(sort -k1,1 -k4,4 tmp) 1a2 > 1 2 3 t 5,6d5 < 1 2 3 t < 23 43 53 q 7a7 > 23 43 53 q
And I looked at the sort page. The man sort page says:
-k, --key=POS1[,POS2] start a key at POS1 (origin 1), end it at POS2 (default end of line)
But I do not understand this explanation. If it starts with POS1 and ends with POS2, then the shouln't # 1 and # 3 commands give the same results?
source share