1

输入文件

1,A,SDF,24,55,55
2,T,AAS,22,12,32
3,TR,SS,14,19,69
4,DD,DD,14,59,39
5,SW,DD,14,39,59
6,SB,DS,12,26,126
7,QQ,SWD,12,19,199
8,QA,DD,12,17,167
9,AA,QQ,10,9,49

期望的输出

1,A,SDF,24,55,55
2,T,AAS,22,12,32
3,TR,SS,14,19,69
5,SW,DD,14,39,59
4,DD,DD,14,59,39
7,QQ,SWD,12,19,199
8,QA,DD,12,17,167
6,SB,DS,12,26,126
9,AA,QQ,10,9,49

逻辑:首先按第 4 列反向排序,然后按第 6 列反向排序

我尝试了以下但没有奏效

sort -t ',' -nrk 4,6 -s Input_file

sort -t ',' -k 4,4n -k 6,6n Input_file
4

2 回答 2

4

我懂了:

kent$  sort -nrt, -k4,4 -k6,6 file                                                                                                                                        
1,A,SDF,24,55,55
2,T,AAS,22,12,32
3,TR,SS,14,19,69
5,SW,DD,14,39,59
4,DD,DD,14,59,39
7,QQ,SWD,12,19,199
8,QA,DD,12,17,167
6,SB,DS,12,26,126
9,AA,QQ,10,9,49
于 2013-05-16T10:52:29.527 回答
3

您可能对 Perl 解决方案感兴趣:

print join(',', @$_), "\n" for 
sort { $b->[3] <=> $a->[3] or $b->[5] <=> $a->[5] }
map { chomp; [ split /,/ ] } <>;
于 2013-05-16T11:50:35.490 回答