How are following sort 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
Especially, #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 did look at the sort's man page In sort's man page, it says:
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of line)
But I don't understand this explanation. If it starts from POS1 and end it at POS2, then shouln't #1 and #3 commands above produce the same results?