0

I'm having problem with sort -g (i.e. general numeric sort) command when run via ssh. Example correct run on a file with 4 lines:

sort -g foo
9.1e-02
0.1
0.5
10.

cat foo
0.5
0.1
9.1e-02
10.

I've recently installed Ubuntu 20.04 and I'm using the default terminal. When I ssh from that terminal to the same machine as used above, then I get incorrect result:

sort -g foo
0.1
0.5
9.1e-02
10.

It seems like some error caused by the terminal from which I ssh. I've tried to find an option in Preferences, but haven't found anything that seemed related. Please let me know what other info I should add.

Edit 1

locale for well-working system and terminal:

LANG=en_US.UTF-8
LC_CTYPE=pl_PL
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE=POSIX
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

for the one with bug:

LANG=en_US.UTF-8
LC_CTYPE=pl_PL
LC_NUMERIC=pl_PL.UTF-8
LC_TIME=pl_PL.UTF-8
LC_COLLATE=POSIX
LC_MONETARY=pl_PL.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=pl_PL.UTF-8
LC_NAME=pl_PL.UTF-8
LC_ADDRESS=pl_PL.UTF-8
LC_TELEPHONE=pl_PL.UTF-8
LC_MEASUREMENT=pl_PL.UTF-8
LC_IDENTIFICATION=pl_PL.UTF-8
LC_ALL=
7
  • 1
    Different LC_NUMERIC is the culprit. Now you (we) need to investigate why the difference. Jul 31, 2020 at 15:45
  • Thanks. I've found that I had to comment SendEnv LANG LC_* in /etc/ssh/ssh_config. Now sort -g works fine.
    – rpoleski
    Jul 31, 2020 at 15:53
  • Great. Write a good answer and I will upvote it. Jul 31, 2020 at 15:54
  • You should write an answer and then I'll upvote and accept it.
    – rpoleski
    Jul 31, 2020 at 15:56
  • Numeric sort in Poland is the same as in other countries. When I do (echo 0.1; echo 9.1e-02) | LC_NUMERIC=pl_PL.UTF-8 sort -g or (echo 0.1; echo 9.1e-02) | LC_ALL=pl_PL.UTF-8 sort -g I get the same correct sort order as with other countries. So there must be some cause other than just the LC_* environment variables.
    – Juergen
    Jul 31, 2020 at 16:11

2 Answers 2

1

The root cause is the use of a locale that defines the decimal_point as comma (like in Poland or Germany) while having decimal points in the input data.

A workaround is to make the sort independent of current locale settings by using
LC_ALL=C sort -g
instead of sort -g.

1

The problem was that Ubuntu was by default forwarding locale settings. It was enough to comment out the line SendEnv LANG LC_* in /etc/ssh/ssh_config.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .