【发布时间】:2010-05-30 09:03:36
【问题描述】:
我希望使用在第二个字段中找到的数值对一个空格分隔的table 进行排序。我可以假设第二个字段总是 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 起作用?
【问题讨论】:
-
sort -n -k.5是指sort -n -k2.5? -
@dalle,是的,你是对的。固定。
标签: sorting command-line command gnu gnu-sort