gnu sort中的--general-numeric-sort和--numeric-sort选项有什么区别 [英] What's the difference between --general-numeric-sort and --numeric-sort options in gnu sort

查看:126
本文介绍了gnu sort中的--general-numeric-sort和--numeric-sort选项有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sort提供两种数字排序.这是来自手册页:

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

   -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之后) sort只是一种常规的字母排序,它知道10在9之后.

General numeric sort compares the numbers as floats, this allows scientific notation eg 1.234E10 but is slower and subject to rounding error (1.2345678 could come after 1.2345679), numeric sort is just a regular alphabetic sort that knows 10 comes after 9.

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

-g"-general-numeric-sort" ``--sort = general-numeric''排序 在数值上使用标准C 函数strtod转换的前缀 每行要双精度 浮点数.这允许 要指定的浮点数 用科学记数法表示,例如1.0e-34 和10e100. LC_NUMERIC语言环境 确定小数点 特点.不报告溢出, 下溢或转换错误.使用 以下整理顺序: 不以数字开头的行 (都被认为是平等的).钠盐 (IEEE中的非数字"值 浮点运算) 一致但与机器有关 命令.负无穷大.有限 数字按升序排列 (-0和+0相等).加 无限.

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

仅当没有时才使用此选项 选择;它比慢得多 --numeric-sort(-n),转换为时可能会丢失信息 浮点.

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"-数字排序""--sort =数字" 按数字排序.号码开始 每行,由可选 空白,可选的-"号和零 或更多可能由分隔的数字 千个分隔符(可选) 后跟小数点字符 以及零个或多个数字.一个空的 数字被视为"0".这 LC_NUMERIC语言环境指定 小数点字符和千位 分隔器.默认情况下,空白为 空格或制表符,但LC_CTYPE 语言环境可以更改此设置.

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

前导"+"或指数均不 表示法被识别.比较 这样的字符串在数字上,请使用 --general-numeric-sort(-g)选项.

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

这篇关于gnu sort中的--general-numeric-sort和--numeric-sort选项有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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