bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #20883] sort -u -n drops more lines than expected


From: Bob Proulx
Subject: [bug #20883] sort -u -n drops more lines than expected
Date: Fri, 24 Aug 2007 07:32:14 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070723 Iceweasel/2.0.0.6 (Debian-2.0.0.6-0etch1)

Update of bug #20883 (project coreutils):

             Assigned to:                    None => rwp                    
             Open/Closed:                    Open => Closed                 

    _______________________________________________________

Follow-up Comment #1:

Thanks for the report but this is not a bug but simply a misunderstanding of
what sort is using as a sort key.  Note that since this is an anonymous bug
posting I cannot respond other than by posting a response to the bug.

By default sort will consider the entire line as the sort key.  When using
the -n numeric sort flag this is still true.  The reason sort -u is collapsing
lines is because the sort key cause sort to believe the lines are equivalent. 
Unless -k is specified to restrict the sort key the default key is the entire
line.

The way to sort that input numerically on two different fields is to use the
-k option to select both fields.  Try this:

  sort -k1,1n -k2,2n -u
  1 1
  1 2
  1 3
  2 1
  3 1

That will provide the result that you are looking to achieve.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?20883>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]