On 10/14/2010 08:28 AM, jack alibaba wrote:
BTW: the email address of the author 'mike' in
coreutils-5.93/src/sort.c is invalid~~~.
Consider upgrading - the latest stable version is 8.5, with 8.6 due
shortly, and there have been a LOT of bug fixes to sort in the meantime.
bash#> (echo 1230 1;echo 123 1)|sort -k1
1230 1
123 1
bash#> (echo 1230 1;echo 123 0)|sort -k1
123 0
1230 1
> I'm not sure if it is my mistake or a bug~~~
Using the new 'sort --debug' feature of coreutils 8.6 shows that the bug
is in your usage, and not in sort:
$ (echo 1230 1; echo 123 1) | src/sort --debug -k1
src/sort: using `en_US.UTF-8' sorting rules
src/sort: leading blanks are significant in key 1; consider also
specifying `b'
1230 1
______
______
123 1
_____
_____
$ (echo 1230 1; echo 123 1) | src/sort --debug -k1,1
src/sort: using `en_US.UTF-8' sorting rules
src/sort: leading blanks are significant in key 1; consider also
specifying `b'
123 1
___
_____
1230 1
____
______
$ (echo 1230 1; echo 123 1) | LC_ALL=C src/sort --debug -k1
src/sort: using simple byte comparison
123 1
_____
_____
1230 1
______
______
Thus, you have two bugs - you probably weren't careful with your locale
(and some locales, like en_US.UTF-8, ignore whitespace when collating),
and you weren't sorting on JUST column 1, but on the entire string (-k1
vs. -k1,1).
--
Eric Blake [email protected] +1-801-349-2682
Libvirt virtualization library http://libvirt.org