What's the difference between --general-numeric-sort and --numeric-sort options in gnu sort

前端 未结 3 788
野趣味
野趣味 2020-12-02 11:55

sort provides two kinds of numeric sort. This is from the man page:

   -g, --general-numeric-sort
          compare according to general numeric         


        
3条回答
  •  天涯浪人
    2020-12-02 12:11

    You should be careful with your locale. For example, you might intend to sort a floating number (like 2.2) whereas your locale might expect the use of a comma (like 2,2).

    As reported in this forum, you may have wrong results using the -n or -g flags.

    In my case I use:

    LC_ALL=C sort -k 6,6n file
    

    in order to sort the 6th column that contains:

    2.5
    3.7
    1.4
    

    in order to obtain

    1.4
    2.5
    3.7
    

提交回复
热议问题