Bash: sort numbers with exponents

前端 未结 4 596
离开以前
离开以前 2021-02-07 03:25

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 so

4条回答
  •  遥遥无期
    2021-02-07 03:51

    I don't have enough rep. to comment, so I am writing this to complement the accepted answer:

    for those who have locales which use a comma instead of a period to indicate decimals, the sorting of decimals will not work properly, as pointed out by HongboZhu

    Solution: the sorting of lists with period-delimited numbers will work properly when using something like the following command (important is the LC_ALL=C):

    ls yourFolder|LC_ALL=C sort -g
    

    This solution comes from the following post: https://unix.stackexchange.com/questions/506965/bash-sort-g-does-not-work-properly

提交回复
热议问题