Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 9
    Could you please explain this strange notation? Commented Oct 24, 2012 at 12:19
  • 1
    This got me thinking along the right lines - thanks for that. But don't you need to specify the stop point for the second -k. That is -k2,2 -k1,1 otherwise the stop point is taken as end of line? Commented Oct 26, 2012 at 7:45
  • 1
    @TonyBedford, correct. But not specifying the stop position will not change the result for your current input, but will force consistency in case you will ever have multiple lines with identical field 2 and 1. So I prefer to allow the last -k to include as much as it can. Commented Oct 26, 2012 at 8:01
  • 2
    @manatwork That should not be necessary; if all the specified fields compare equal, sort will compare the entire line. Or with GNU sort you can use -s for stable sort. Commented Mar 2, 2015 at 19:08