After more investigation, I realized that it might be an locale specific behavior.
On this website, and also on my computer:
someone@debian:~$ locale | grep LC_NUMERIC
LC_NUMERIC="en_US.UTF-8"
someone@debian:~$ echo '48,39.8-56.3
50.7,39.6-61.8
50.7,39' | sort -t ',' -k 1nr --debug
sort: text ordering performed using ‘en_US.UTF-8’ sorting rules
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a group separator in numbers
48,39.8-56.3
50.7,39
50.7,39.6-61.8
someone@debian:~$ echo '48,39.8-56.3
50.7,39.6-61.8
50.7,39' | sort -t ',' -k 1,1nr --debug
sort: text ordering performed using ‘en_US.UTF-8’ sorting rules
sort: note numbers use ‘.’ as a decimal point in this locale
50.7,39
50.7,39.6-61.8
48,39.8-56.3
In the course docker image:
stud@db4803519dd0:~$ locale | grep LC_NUMERIC
LC_NUMERIC="POSIX"
stud@db4803519dd0:~$ echo '48,39.8-56.3
50.7,39.6-61.8
50.7,39' | sort -t ',' -k 1nr --debug
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
sort: note numbers use '.' as a decimal point in this locale
50.7,39
50.7,39.6-61.8
48,39.8-56.3
stud@db4803519dd0:~$ echo '48,39.8-56.3
50.7,39.6-61.8
50.7,39' | sort -t ',' -k 1,1nr --debug
sort: text ordering performed using simple byte comparison
sort: note numbers use '.' as a decimal point in this locale
50.7,39
50.7,39.6-61.8
48,39.8-56.3
So my original post is only partially correct.
-
You MAY get an unexpected result, depending on the locale config of your system.
-
Still, it is better to use 1,1nr
than 1nr
. Actually, sort
will complain if you do not use the suggested form.