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

Michael D. Setzer II mikes at guam.net
Wed Jun 29 07:11:32 UTC 2022


Did a test on Fedora 35 with busybox 1.35.0
This seems to work.
echo  -e "3 March\n2 April" | busybox sort -t\  -k2M

Had to use -e to have it insert new line. 
Then found it didn't work with the default delimiter, but 
using -t\  got it to work. Tried it with a separate -M or the 
M at the end. Both work.

echo  -e "3 March\n2 April" | busybox sort -t\  -k2M
3 March
2 April

More complete test
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" | 
busybox sort -t\  -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

Don't know if it is an issue with the delimiter default or 
what?

Without the -t\  
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" | 
busybox sort -k2M
1 Jan
11 Nov
15 May
2 April
3 March
5 Feb
6 Dec
6 Jun
7 Jul
8 Aug
8 Oct
9 Sep

On 28 Jun 2022 at 22:10, Dennis Chen wrote:

Date sent:      	Tue, 28 Jun 2022 22:10:44 -0700
To:             	<busybox at busybox.net>
Subject:        	sort's -k flag is buggy when M is also 
passed
From:           	"Dennis Chen" <dchen at dennisc.net>

> All commands were run on both Ubuntu busybox v1.30.1 and Alpine busybox
> v1.35.0.
> 
> I ran
> 	echo "3 March\n2 April" | busybox sort -k 2,2M
> and it returned
> 	2 April
> 	3 March
> It should return
> 	3 March
> 	2 April
> and indeed, that is what you get with GNU sort. (It doesn't seem to
> matter what the numbers "2" and "3" are - I replaced them both with the
> string "filler" and got the same result.)
> 
> This seems to only happen when the field number is >1. For instance
> 	echo "March\nApril" | busybox sort -k 1,1M
> correctly outputs
> 	March
> 	April
> 
> It also doesn't happen when M isn't passed into -k. For instance,
> 	echo "a c\nb b" | sort -k 2,2
> correctly returns
> 	b b
> 	a c
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


+------------------------------------------------------------+
 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