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

查看:17
本文介绍了gnu 排序中的 --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’ ‘--numeric-sort’ ‘--sort=numeric’按数字排序.数开始每行由可选的空格、可选的-"符号和零或更多的数字可能被分隔千位分隔符,可选后跟小数点字符和零个或多个数字.一个空的数字被视为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 排序中的 --general-numeric-sort 和 --numeric-sort 选项有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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