加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

unix – 在gnu排序中–general-numeric-sort和–numeric-sort选

发布时间:2020-12-15 16:52:35 所属栏目:安全 来源:网络整理
导读:sort提供了两种数值排序。这是从手册页: -g,--general-numeric-sort compare according to general numerical value -n,--numeric-sort compare according to string numerical value 有什么不同? 通用数字排序将数字比较为浮点数,这允许科学记数法例如1.
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’
‘–sort=general-numeric’ 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. The LC_NUMERIC locale
determines the decimal-point
character. Do not report overflow,
underflow,or conversion errors. Use
the following collating sequence:
Lines that do not start with numbers
(all considered to be equal). NaNs
(“Not a Number” values,in IEEE
floating point arithmetic) in a
consistent but machine-dependent
order. Minus infinity. Finite
numbers in ascending numeric order
(with -0 and +0 equal). Plus
infinity.

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

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

Comparison is exact; there is no
rounding error.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读