当前位置: 技术问答>linux和unix
请问哪位熟悉LINUX 下的SORT命令?
来源: 互联网 发布时间:2016-06-18
本文导语: 我用sort -k 9,10 sortfile -o 1.txt 排列出来的结果总是不对。不是正行排序的。 sortfile文件内容为: peach :2 apple :5 peach1 :1 orange :3 以上命令排序后的结果是: apple :5 orange :3 peach1 :1 peach :2 请问有熟悉的同...
我用sort -k 9,10 sortfile -o 1.txt
排列出来的结果总是不对。不是正行排序的。
sortfile文件内容为:
peach :2
apple :5
peach1 :1
orange :3
以上命令排序后的结果是:
apple :5
orange :3
peach1 :1
peach :2
请问有熟悉的同学吗?
排列出来的结果总是不对。不是正行排序的。
sortfile文件内容为:
peach :2
apple :5
peach1 :1
orange :3
以上命令排序后的结果是:
apple :5
orange :3
peach1 :1
peach :2
请问有熟悉的同学吗?
|
-k后面用的不是字符所在的列,而是所谓的“field number”
field应该就是以空格分隔的,所以第一个field是peach,第二个field是:2
$ man sort
......
-k, --key=POS1[,POS2]
start a key at POS1, end it at POS2 (origin 1) - when no POS2
specified, end of line is used
......
POS is F[.C][OPTS], where F is the field number and C the character
position in the field; both are origin 1. If neither -t nor -b is in
effect, characters in a field are counted from the beginning of the
preceding whitespace. 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.
field应该就是以空格分隔的,所以第一个field是peach,第二个field是:2
$ man sort
......
-k, --key=POS1[,POS2]
start a key at POS1, end it at POS2 (origin 1) - when no POS2
specified, end of line is used
......
POS is F[.C][OPTS], where F is the field number and C the character
position in the field; both are origin 1. If neither -t nor -b is in
effect, characters in a field are counted from the beginning of the
preceding whitespace. 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.
|
如果要按照1、2、3、5所在的位置排序,也可以这样
sort -b -k 2.2 sortfile
sort -b -k 2.2 sortfile
|
排序