What is the difference between sort -t' ' -k1,1n -k2,2n
and sort -t' ' -k1,2n
?
Could you give examples?
I've tried:
logan@logan-mainPC:~/my-test/learn-sort$ cat myage
my age 1
my age 100
my age 2
my age 200
logan@logan-mainPC:~/my-test/learn-sort$ cat myage | sort -k2,3
my age 1
my age 100
my age 2
my age 200
logan@logan-mainPC:~/my-test/learn-sort$ cat myage | sort -k2,2 -k3,3
my age 1
my age 100
my age 2
my age 200
logan@logan-mainPC:~/my-test/learn-sort$ cat myage | sort -k2,2 -k3,3n
my age 1
my age 2
my age 100
my age 200
I think sort -k2,3
sorts 'age 1', 'age 100', ... and sort -k2,2 -k3,3
sorts 'age', 'age',... then '1', '100', .... Since they all treat columns as strings they produce the same outcome.
But sort -k2,2 -k3,3n
produces different outcome because it treats column 3 as numbers.
But then:
logan@logan-mainPC:~/my-test/learn-sort$ cat myage | sort -k2,3n
my age 1
my age 100
my age 2
my age 200
which is strange. Found out the reason is because column 2 is not numbers.
logan@logan-mainPC:~/my-test/learn-sort$ cat myage | sort --debug -k2,3n
sort: using ‘en_AU.UTF-8’ sorting rules
sort: key 1 is numeric and spans multiple fields
my age 1
^ no match for key
________
my age 100
^ no match for key
__________
my age 2
^ no match for key
________
my age 200
^ no match for key
__________
Thanks.