gpt4 book ai didi

sorting - 对数字子字段的 GNU `sort(1)` 感到困惑

转载 作者:行者123 更新时间:2023-12-02 18:38:26 25 4
gpt4 key购买 nike

我希望使用第二个字段中找到的数值对空格分隔的进行排序。我可以假设第二个字段始终是 fooN 但 N 的长度未知:

antiq. foo11 girls
colleaguing foo2 Leinsdorf
Cousy foo0 Montgomeryville
bowlegged foo1 pollack
Chevrier foo10 ill-conceived
candlebomb foo3 seventieths
autochthony foo101 re-enable
beneficiate foo100 osteometric

我读了 man sort(1) 并尝试了各种选项。在我的系统上我发现了这一行:

sort -n -k2.5 table

上类。

我的问题是为什么?

根据手册页:

-k, --key=POS1[,POS2]
start a key at POS1, end it at POS 2 (origin 1)
...
POS is F[.C][OPTS], where F is the field number and C the characterposition in the
field. OPTS is one or more single-letter ordering options, which override global
ordering options for that key. If no key is given, use the entire line as the key.

那么为什么 sort -n -k2.4 表不起作用而 sort -n -k2.5 却起作用?

最佳答案

我不知道这是否有帮助,但是info sort声明如下:

sort -t : -k 2,2n -k 5.3,5.4

 Note that if you had written `-k 2' instead of `-k 2,2' `sort'
would have used all characters beginning in the second field and
extending to the end of the line as the primary _numeric_ key.
For the large majority of applications, treating keys spanning
more than one field as numeric will not do what you expect.

也许尝试在 -k2 之间添加空格,或者尝试设置 POS2

关于sorting - 对数字子字段的 GNU `sort(1)` 感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2938032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com