It's UWAweek 45 (2nd semester, 2nd exam week)

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 the 4 articles in this topic
Showing 4 of 445 articles.
Currently 5 other people reading this forum.


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

Login to reply

👍x1
helpful

Fun fact:

echo '48,39.8-56.3
50.7,39.6-61.8
50.7,39' | sort -t ',' -k 1nr

results in

48,39.8-56.3
50.7,39.6-61.8
50.7,39

This can be fixed by changing 1nr to 1,1nr.

https://superuser.com/questions/33362/how-to-unix-sort-by-one-column-only

Thought I would share with everyone here.


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.


SVG not supported

Login to reply

👍?
helpful
3:12pm Thu 6th Jun, Michael W.

Hi Here is why the representing floating point numbers is locale dependent

https://www.grammar-monster.com/lessons/commas_with_numbers.htm

Cheers MichaelW


SVG not supported

Login to reply

👍?
helpful
3:14pm Thu 6th Jun, Michael W.

This brings me back to an earlier tip: keep things simple, and then - hopefully - portable.

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