Linux的排序不负浮点数工作 [英] Linux sort doesn't work with negative float numbers

查看:121
本文介绍了Linux的排序不负浮点数工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何这种投入的排序?

0.00159265291648695254
-0.00318530179313823899
0
0.00999983333416666468
0.00362937767285478371
0.00477794259012844049
-0.00637057126765263261
0.00681464007477014026
-0.00840724736714870645
-0.00522201549675090458

排序-n数据排序-g数据 procudes这样的:

Either sort -n data and sort -g data procudes this:

0
0.00159265291648695254
-0.00318530179313823899
0.00362937767285478371
0.00477794259012844049
-0.00522201549675090458
-0.00637057126765263261
0.00681464007477014026
-0.00840724736714870645
0.00999983333416666468

在另一方面 -1.whatever 将在零的前面。我需要的那种注意减号。谢谢你。

On the other hand -1.whatever would be in front of the zero. I need the sort to notice the minus signs. Thank you.

推荐答案

所有这些麻烦做我的本地设置。我的Ubuntu是捷克:

All those troubles did my local settings. My ubuntu is in Czech:

$ echo $LANG
cs_CZ.UTF-8

在这个地方设置,它不是一个小数点,而小数逗号将其与其他的方式隔开的整数(如我们在数学课被认为,在我们的语言,我们确实写逗号而不是一个点)。

In this local setting it's not a decimal point, rather a decimal comma that seperates integer from the rest (as we were thought in math classes, in our language we really do write comma instead of a point).

因此​​:

echo '0,03 >> 0,4 >
> -0,3 >
> 0' | sort -n
> 0
> -0,3 >
> 0,4 >
0,03 >

如果你正在写一个bash脚本,设置排序例程使用正常的设置。

If you are writing a bash script, set the sorting routine to use the "normal" settings.

export LC_ALL=C

这篇关于Linux的排序不负浮点数工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆