I have an input file with the following data:
AUD 100 20
USD 200 30
INR 10 20
AUD 100 30
USD 200 40
EUR 50 60
EUR 50 70
AUD 100 11
USD 200 55
INR 10 35
I run:
cat filename | sort -u -k1,2
He gives me a conclusion as follows:
AUD 100 20
EUR 50 60
INR 10 20
USD 200 30
So, I understand that it sort -u k1,2
sorts the data and gives the result based on a unique combination of values in columns # 1 and # 2. Now, based on this understanding, I run:
cat filename | sort -u -k1
to get the result based on the unique values in column # 1. Therefore, I expected this conclusion:
AUD 100 20
EUR 50 60
INR 10 20
USD 200 30
But the actual result was:
AUD 100 11
AUD 100 20
AUD 100 30
EUR 50 60
EUR 50 70
INR 10 20
INR 10 35
USD 200 55
USD 200 30
USD 200 40
Can someone explain what happens to the option sort -u -km,n?
Vicky source
share