[prev in list] [next in list] [prev in thread] [next in thread] 

List:       coreutils-bug
Subject:    bug#24906: gnu sort, what am I doing wrong?
From:       arnold () skeeve ! com
Date:       2016-11-09 14:11:23
Message-ID: 201611091411.uA9EBNgO002413 () freefriends ! org
[Download RAW message or body]

Hi Assaf.

Much thanks for the explanation. That makes sense and helps a lot.

Arnold

Assaf Gordon <assafgordon@gmail.com> wrote:

> Hello Arnold,
>
> > On Nov 8, 2016, at 23:23, Arnold Robbins <arnold@skeeve.com> 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
>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic