-g, --general-numeric-sort, --sort=general-numeric
Sort by general numerical value. As opposed to -n, this option
handles general floating points. It has a more permissive format
than that allowed by -n but it has a significant performance
drawback.
...
-n, --numeric-sort, --sort=numeric
Sort fields numerically by arithmetic value. Fields are supposed
to have optional blanks in the beginning, an optional minus sign,
zero or more digits (including decimal point and possible thou-
sand separators).
...
STANDARDS
The sort utility is compliant with the IEEE Std 1003.1-2008 (``POSIX.1'')
specification.
The flags [-ghRMSsTVz] are extensions to the POSIX specification.
...
NOTES
...
When sorting by arithmetic value, using -n results in much better perfor-
mance than -g so its use is encouraged whenever possible.
TL;博士
虽然
-n
将对简单的浮点数进行排序,例如1.234
,该-g
选项处理范围更广的数字格式,但速度较慢。也是
-g
POSIX 规范的 GNU 扩展。从
man sort
,相关部分是:但是,完整的文档由
info
而不是提供man
。从7.1 sort: Sort text files开始,描述/区分更加清晰:
快速演示: