GNU bug report logs -
#24906
gnu sort, what am I doing wrong?
Previous Next
Reported by: Arnold Robbins <arnold <at> skeeve.com>
Date: Wed, 9 Nov 2016 04:24:01 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 24906 <at> debbugs.gnu.org (full text, mbox):
Hello Arnold,
> On Nov 8, 2016, at 23:23, Arnold Robbins <arnold <at> 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
This bug report was last modified 6 years and 206 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.