sort's -k flag is buggy when M is also passed

Michael D. Setzer II mikes at guam.net
Wed Jun 29 17:37:08 UTC 2022


On 29 Jun 2022 at 10:18, Dennis Chen wrote:

Date sent:      	Wed, 29 Jun 2022 10:18:10 -0700
Copies to:      	Subject:        	Re: sort's -k flag is buggy 
when M is also passed
From:           	"Dennis Chen" <dchen at dennisc.net>
To:             	<mikes at guam.net>, 
<busybox at busybox.net>

> > Had to use -e to have it insert new line. 
> 
> FWIW, I was able to get your tests to work without -e. (Alpine, busybox 1.35.0)
> 
> > Looking at sort.c in busybox seems that
> > static char key_separator; is just defined, but not
> > assigned a default value?
> > Don't know if this might resolve issue?
> > static char key_separator=' ';
> 
> Using -t ' ' might work for some cases, but consider
> 	abc March 3
> 	de  April 2
> This example is a little contrived, but you might easily see something
> like this in the real world (think logfiles).

Good point think the regular sort talks about the 
separator been change from blank non-blank, and that 
would ge a little more of a issue.

I had modified the sort.c with the =' '; and it seemed to 
work. For you issue I inserted a tr -s ' ' that would convert 
multiple spaces to a single space. If added spaces before 
number would need to change the 2 to 3 I believe.

echo  -e "3  March\n2 April\n1  Jan\n5   Feb\n6   Dec\n8 
Oct\n7 Jul\n6 Jun\n8   Aug\n15 May\n11   Nov\n9 Sep" | tr 
-s ' ' |./busybox sort -k2M
1 Jan
5 Feb
3 March
2 April
15 May
6 Jun
7 Jul
8 Aug
9 Sep
8 Oct
11 Nov
6 Dec

echo  -e "  3  March\n  2 April\n  1  Jan\n  5   Feb\n 6   
Dec\n 8 Oct\n 7 Jul\n  6 Jun\n  8   Aug\n  15 May\n  11   
Nov\n  9 Sep" | tr -s ' ' |./busybox sort -k3M
 1 Jan
 5 Feb
 3 March
 2 April
 15 May
 6 Jun
 7 Jul
 8 Aug
 9 Sep
 8 Oct
 11 Nov
 6 Dec

+------------------------------------------------------------+
 Michael D. Setzer II - Computer Science Instructor 
(Retired)     
 mailto:mikes at guam.net                            
 mailto:msetzerii at gmail.com
 Guam - Where America's Day Begins                        
 G4L Disk Imaging Project maintainer 
 http://sourceforge.net/projects/g4l/
+------------------------------------------------------------+





More information about the busybox mailing list