我试图用这样的数值对一个文件进行排序:
414e-05
435e-05
0.5361
0.7278
0.1341
0.9592
0.2664
通过排序,所有数字都得到排序,除了带有指数的数字,排序函数是否有某种方法来计算这个表达式?
最佳答案
如果你的排序命令版本足够新,它应该支持 -g 选项(或者 --general-numeric-sort) 如果你喜欢你的选项长的)。在信息手册中是这样描述的:
Sort numerically, using the standard C function
strtod
to convert a prefix of each line to a double-precision floating point number. This allows floating point numbers to be specified in scientific notation, like '1.0e-34' and '10e100'.
关于Bash:用指数对数字进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4324923/