I have a tab-delimited file with three columns like this:

joe W 4
bob A 1
ana F 1
roy J 3
sam S 0
don R 2
tim L 0
cyb M 0

I want to sort this file by decreasing values in the third column, but to break ties I do not want to use some other column to do so (i.e. not use the first column to sort rows with the same entry in the third column).

Instead, I want rows with the same third column entries to either preserve the original order, or be sorted randomly.

Is there a way to do this using the sort command in unix?

  • Does your sort command support a -s option? Feb 27, 2015 at 7:50
  • Yes. This is exactly the solution I'm looking for. Thanks!
    – Arjun
    Feb 27, 2015 at 19:41

1 Answer 1


For the first part, you can use the -k option of sort :

sort -k 3 -r

I don't really understand what you want to do with ties...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.