原帖由 rhlei 于 2009-4-13 08:18 发表 ![]()
sort -t, +3 +2 test.txt 先以第四字段为第一排序段,然后是三
sort -t, -k4 -k3 test.txt 同上
你对sort -k的理解是错的
-k, --key=POS1[,POS2]
start a key at POS1, end it at POS2 (origin 1)
[root@Mylinux tmp]# cat file
a1,9,2,21
a2,9,4,11
b1,8,7,15
b2,8,1,17
c1,7,6,24
c2,7,3,13
[root@Mylinux tmp]# sort -t, -k2 -k4 file
c2,7,3,13
c1,7,6,24
b2,8,1,17
b1,8,7,15
a1,9,2,21
a2,9,4,11
[root@Mylinux tmp]# sort -t, -k2,2 -k4,4 file
c2,7,3,13
c1,7,6,24
b1,8,7,15
b2,8,1,17
a2,9,4,11
a1,9,2,21
我举的例子中sort -t, -k2 -k4只是等同于sort -t, -k2
[root@Mylinux tmp]# sort -t, -k2 file
c2,7,3,13
c1,7,6,24
b2,8,1,17
b1,8,7,15
a1,9,2,21
a2,9,4,11
[ 本帖最后由 ywlscpl 于 2009-4-13 08:44 编辑 ] |