Subject: Re: bug#65342: In Ubuntu 22.04 (unlike 20.04), sorting doesn't work properly

From: Pádraig Brady <[email-masked]>
Date: Wed, 16 Aug 2023 19:07:56 +0100

tag 65342 notabug
close 65342
stop

more info below...

On 16/08/2023 16:55, Pl B wrote:
> Source file:
> rs1009150173,100202244031
> rs1009150172,13853975996
> rs1009150170,54321425962
> rs1009150171,11378896079
> rs1009150,171582090052
> 
> Ubuntu 20.04.5:
> sort -t ',' /path/to/rs_srt_exp.txt
> rs1009150,171582090052
> rs1009150170,54321425962
> rs1009150171,11378896079
> rs1009150172,13853975996
> rs1009150173,100202244031
> (correct order)
> 
> elementary OS 7 (Ubuntu 22.04.3):
> sort -t ',' /path/to/rs_srt_exp.txt
> rs1009150170,54321425962
> rs1009150171,11378896079
> rs1009150,171582090052
> rs1009150172,13853975996
> rs1009150173,100202244031
> (wrong order)
> 
> Python 3.10.12:
> with open('/path/to/rs_srt_exp.txt') as src_file_opened:
>      for elem in sorted(map(lambda line: line.rstrip().split(','),
> src_file_opened)):
>          print(elem)
> ['rs1009150', '171582090052']
> ['rs1009150170', '54321425962']
> ['rs1009150171', '11378896079']
> ['rs1009150172', '13853975996']
> ['rs1009150173', '100202244031']
> (correct order)

-t is ineffective without -k
I suspect the differing orders were due to locale differences.
To get expected ordering you probably want something like:

   sort -t ',' -k1.3,1n -k2,2n

Note the --debug option is useful for identifying how sort is operating.

cheers,
Pádraig