sort by multiple columns
hi all I have file:
154 alfonz novak 154 michael cores 62 jan nedorost 62 martin adrov and I want to sort by first column numericaly and then by third column alphabeticaly. so output should be: 62 martin adrov 62 jan nedorost 154 michael cores 154 alfonz novak I tried Code:
sort -k1n,3 sort 62 jan nedorost 62 martin adrov 154 alfonz novak 154 michael cores what I am doing wrong ? Thanks |
Note: This way to do it is wrong, see below.
Code:
bash-3.1$ echo ' Code:
sort -k1r sort |
I think this will cover what you're asking for:
Code:
sort -k1,1r -k3 names |
Quote:
Code:
telemachus ~ $ cat names |
Oh, yeah, oops. You're right, there should be another one, my bad.
|
Thanks guys, I did not know I can put another -k options. so my code looks like
Code:
sort -k1n -k3 names Just for curiosity what is difference between "-k1n,3" and "-k1n -k3" teoreticaly both should do the same thing but practice is different |
All times are GMT -5. The time now is 08:07 PM. |