bug-coreutils
[Top][All Lists]
Advanced

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

bug#24906: gnu sort, what am I doing wrong?


From: Assaf Gordon
Subject: bug#24906: gnu sort, what am I doing wrong?
Date: Wed, 9 Nov 2016 01:14:35 -0500

Hello Arnold,

> On Nov 8, 2016, at 23:23, Arnold Robbins <address@hidden> wrote:
> 
> $ grep -v ^# checkbook.txt | sort -t: -k5 -k6rg
> [...]
> Why aren't these sorted by amounts in descending order?
> What am I missing?

The option "-k5" means "field 5 till the end of the line", which includes field 
6.
e.g "W:10.00" sorts before "W:35.00".
You likely want "-k5,5" which means "field 5 only".

The "--debug" option will show which part of each line is taken as the sorting 
key:
===
$ grep -v ^# checkbook.txt | sort --debug -t: -k5 -k6rg
sort: using ‘en_US.UTF-8’ sorting rules
sort: key 2 is numeric and spans multiple fields
2016:1:31:O'Reilly Media:D:100.00
                         ________
                           ______
_________________________________
2015:12:10:Joe's Coffee:W:10.00
                        _______
                          _____
_______________________________
2015:12:15:Mary's Doughnuts:W:10.00
                            _______
                              _____
___________________________________
2016:1:2:Hank's Party Store:W:35.00
                            _______
                              _____
___________________________________
2015:11:12:Mary's Doughnuts:W:5.00
                            ______
                              ____
__________________________________
2015:11:9:Joe's Coffee:W:5.00
                       ______
                         ____
_____________________________

===

versus:

===
$ grep -v ^# checkbook.txt | sort --debug -t: -k5,5 -k6,6rg
sort: using ‘en_US.UTF-8’ sorting rules
2016:1:31:O'Reilly Media:D:100.00
                         _
                           ______
_________________________________
2016:1:2:Hank's Party Store:W:35.00
                            _
                              _____
___________________________________
2015:12:10:Joe's Coffee:W:10.00
                        _
                          _____
_______________________________
2015:12:15:Mary's Doughnuts:W:10.00
                            _
                              _____
___________________________________
2015:11:12:Mary's Doughnuts:W:5.00
                            _
                              ____
__________________________________
2015:11:9:Joe's Coffee:W:5.00
                       _
                         ____
_____________________________
===

regards,
 - assaf






reply via email to

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