It's UWAweek 47

helpOSTS

This forum is provided to promote discussion amongst students enrolled in Open Source Tools and Scripting.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying selected article
Showing 1 of 445 articles.
Currently 48 other people reading this forum.


 UWA week 23 (1st semester, 1st exam week) ↓
SVG not supported

Login to reply

👍?
helpful

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.

  1. You MAY get an unexpected result, depending on the locale config of your system.

  2. Still, it is better to use 1,1nr than 1nr. Actually, sort will complain if you do not use the suggested form.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy