我正在遵循这个脚本并尝试了解每一行发生的情况。从此处提取的以下行涉及对一些字段进行排序。在这里给出的第 14 个示例中,它表示-k2,5代表对作为数值的列 2 和 5 进行排序,并-k9代表对作为非数字值列的第 9 列进行排序。
# Process the STMs
cat db/TEDLIUM_release1/$set/stm/*.stm | sort -k1,1 -k2,2 -k4,4n | \
sed -e 's:<F0_M>:<o,f0,male>:' \
-e 's:<F0_F>:<o,f0,female>:' \
-e 's:([0-9])::g' \
-e 's:<sil>::g' \
-e 's:([^ ]*)$::' | \
awk '{ $2 = "A"; print $0; }'
} | local/join_suffix.py db/TEDLIUM_release1/TEDLIUM.150K.dic > data/$set/stm
Run Code Online (Sandbox Code Playgroud)
但在上面的代码段(sort -k1,1 -k2,2 -k4,4n)中,它映射-k1,1并且也有 3 组。有人可以帮助我理解这一点吗?
从man sort:
-k, --key=POS1[,POS2]\n start a key at POS1 (origin 1), end it at POS2 (default end of line)\n...\n\nPOS is F[.C][OPTS], where F is the field number and C the character position\nin the field; both are origin 1. If neither -t nor -b is in effect,\ncharacters in a field are counted from the beginning of the preceding\nwhitespace. OPTS is one or more single-letter ordering options, which\noverride global ordering options for that key. If no key is given, use the\nentire line as the key.\nRun Code Online (Sandbox Code Playgroud)\n\n您发布的链接中的第 14 个示例根本不正确。从上面的手册页摘录中可以很清楚地看出,-k2,5不会“基于键 2 和 5”进行排序,而是基于字段 2到5,将所有这些一起算作单个排序键。
(顺便说一句:来自随机在线资源的代码示例非常适合粗略地了解该命令的用途或功能,但是当您想深入研究并真正了解发生了什么时,没有替代品用于阅读\xe2\x80\x94或至少查阅\xe2\x80\x94手册页。) ;)
\n