unix sort multiple fields

Viewed 22655

I'm trying to sort the file below as follows:

col1 (Ascending) col2 (Descending) col3 (Ascending) col4 (Descending)

I want to use the -k command, not the +- syntax. I've figured out how to use the old syntax:

sort -t " " +0 -1 +2 -3 +4r testfile

but it's hardly intuitive. I haven't figured out the right way to use the -k option. Thank you.

Here's the testfile:

5 3 2 9
3 4 1 7
5 2 3 1
6 1 3 6
1 2 4 5
3 1 2 3
5 2 2 3

Result:

1 2 4 5
3 4 1 7
3 1 2 3
5 3 2 9
5 2 2 3
5 2 3 1
6 1 3 6
2 Answers
Related