I have a file:
$ cat file
1 c
8 a
1 b
5 f
I think the sort
command in the beginning compares the first field of all lines and sorts them then for those lines have equal first fields and starts sorting again for second fields like this:
$sort file
1 b
1 c
5 f
8 a
I read about the difference between the options k 1
and k 1,1
: with k 1
it is possible the sort key continues to the end of the line but with k 1,1
it should sort only the first field without considering other fields but:
$sort -k 1 file
1 b
1 c
5 f
8 a
$sort -k 1,1 file
1 b
1 c
5 f
8 a
Why are the outputs of sort
= sort k 1
= sort k 1,1
equal?
I think the output of sort k 1,1 file
should be
1 c
1 b
5 f
8 a
If it is not correct please tell me what is my mistake and how can I get output like that?
From
info sort
So to achieve your desired result (bearing in mind your first field is numeric)
If you want the second column to be reversed (it is not a proper answer to your specific question, but maybe it is what you are interested in), elaborating a bit from Unix StackExchange one gets: