bug-coreutils
[Top][All Lists]
Advanced

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

Re: problem with command sort after uniq -c


From: Philip Rowlands
Subject: Re: problem with command sort after uniq -c
Date: Mon, 10 Mar 2008 18:26:12 +0000 (GMT)

On Mon, 10 Mar 2008, Damien ANCELIN wrote:

I met a problem with the sort command : I've used the uniq command with the -c option to count some numbers, and then applying sort -n don't sort lines by numeric order of the first field.
Here is an example (my sort version is 5.97) :
$ cat bug_sort | sort -n
  1320 51970
  1692 12345
 22681 8060
 26063 8649
  2668 33603
  3487 44496
  4350 23246
 47013 8000
 5447 20000
81724 5000

You don't say which locale your environment is configured to use for sorting, but I'd bet it's one which treats whitespace differently to how you expect.

With only spaces between the 2 fields, sort -n read 1 number per line and use it to do the sort : 2668 33603 is read as 266833603. With this consideration, the result of sort is correct, but it's not what I expected (and I didn't see this behaviour in the documentation).

The command "sort -n" treats the whole line as the sort key. Specifying "sort -k1,1n" will use just the first field, in ascending numerical order.


Cheers,
Phil




reply via email to

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