How to UNIX sort by one column only?

Posted by ssn on Super User See other posts from Super User or by ssn
Published on 2009-08-31T16:20:22Z Indexed on 2010/03/15 0:30 UTC
Read the original article Hit count: 709

Filed under:
|

I know that the -k option for the Unix sort allow us to sort by a specific column and all of the following. For instance, given the input file:

2 3
2 2
1 2
2 1
1 1

Using sort -n -k 1, I get an output sorted by the 1st column and then by the 2nd:

1 1
1 2
2 1
2 2
2 3

However, I want to keep the 2nd column ordering, like this:

1 2
1 1
2 3
2 2
2 1

Is this possible with the sort command?

© Super User or respective owner

Related posts about unix

Related posts about sort