unix – 在gnu排序中–general-numeric-sort和–numeric-sort选项之间的区别是什么

前端之家收集整理的这篇文章主要介绍了unix – 在gnu排序中–general-numeric-sort和–numeric-sort选项之间的区别是什么前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
sort提供了两种数值排序。这是从手册页:
-g,--general-numeric-sort
          compare according to general numerical value

   -n,--numeric-sort
          compare according to string numerical value

有什么不同?

通用数字排序将数字比较为浮点数,这允许科学记数法例如1.234E10,但是更慢,并受舍入误差(1.2345678可能来自1.2345679之后),数字排序只是一个常规的字母排序,知道10后9。

http://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html

‘-g’ ‘–general-numeric-sort’@H_502_13@ ‘–sort=general-numeric’ Sort@H_502_13@ numerically,using the standard C@H_502_13@ function strtod to convert a prefix of@H_502_13@ each line to a double-precision@H_502_13@ floating point number. This allows@H_502_13@ floating point numbers to be specified@H_502_13@ in scientific notation,like 1.0e-34@H_502_13@ and 10e100. The LC_NUMERIC locale@H_502_13@ determines the decimal-point@H_502_13@ character. Do not report overflow,@H_502_13@ underflow,or conversion errors. Use@H_502_13@ the following collating sequence:@H_502_13@ Lines that do not start with numbers@H_502_13@ (all considered to be equal). NaNs@H_502_13@ (“Not a Number” values,in IEEE@H_502_13@ floating point arithmetic) in a@H_502_13@ consistent but machine-dependent@H_502_13@ order. Minus infinity. Finite@H_502_13@ numbers in ascending numeric order@H_502_13@ (with -0 and +0 equal). Plus@H_502_13@ infinity.

Use this option only if there is no@H_502_13@ alternative; it is much slower than@H_502_13@ –numeric-sort (-n) and it can lose information when converting to@H_502_13@ floating point.

‘-n’ ‘–numeric-sort’ ‘–sort=numeric’@H_502_13@ Sort numerically. The number begins@H_502_13@ each line and consists of optional@H_502_13@ blanks,an optional ‘-’ sign,and zero@H_502_13@ or more digits possibly separated by@H_502_13@ thousands separators,optionally@H_502_13@ followed by a decimal-point character@H_502_13@ and zero or more digits. An empty@H_502_13@ number is treated as ‘0’. The@H_502_13@ LC_NUMERIC locale specifies the@H_502_13@ decimal-point character and thousands@H_502_13@ separator. By default a blank is a@H_502_13@ space or a tab,but the LC_CTYPE@H_502_13@ locale can change this.

Comparison is exact; there is no@H_502_13@ rounding error.

Neither a leading ‘+’ nor exponential notation is recognized. To compare such strings numerically,use the –general-numeric-sort (-g) option.

猜你在找的Bash相关文章