重击:用指数对数字进行排序 [英] Bash: sort numbers with exponents

查看:110
本文介绍了重击:用指数对数字进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用这样的数值对一个文件进行排序:

I was trying to sort one file with numeric values like this:

414e-05
435e-05
0.5361
0.7278
0.1341
0.9592
0.2664

通过排序,除具有指数的数字外,所有数字均被排序,是否有某种方法可以使排序函数计算该表达式?

With sort all the numers get sorted except for the ones with the exponent, is there some way for sort function to evaluate this expression?

推荐答案

如果您的sort命令版本足够新,则它应支持 -g 选项(或-general -numeric-sort)(如果您希望长期选择).信息手册中对此进行了描述:

If your version of the sort command is new enough, it should support the -g option (or --general-numeric-sort) if you like your options long). It is described like this in the info manual:

使用标准C函数strtod进行数字排序 将每行的前缀转换为双精度浮点 数字.这允许以科学的方式指定浮点数 表示法,例如"1.0e-34"和"10e100".

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'.

这篇关于重击:用指数对数字进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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