2015-10-23 38 views
0

我的文件看起来像这样:订单通过柱2的一个子然后通过柱1的bash

0.3 test_a1 
0.2 test_a1 
0.4 test_a1 
0.1 test_a21 
0.9 test_a21 
0.5 test_a21 
0.3 test_b99 
0.2 test_b99 

每个组是第2列,而不在端部的数目(在上述例子中的两个基团是test_a和test_b)。我想组,然后才能通过列1至顺序,以便正确的结果是:

0.1 test_a21 
0.2 test_a1 
0.3 test_a1 
0.4 test_a1 
0.5 test_a21 
0.9 test_a21 
0.2 test_b99 
0.3 test_b99 

下面的命令给出了错误的结果:

sort -t' ' -k2,2 -k1 file.txt 

0.2 test_a1 
0.3 test_a1 
0.4 test_a1 
0.1 test_a21 
0.5 test_a21 
0.9 test_a21 
0.2 test_b99 
0.3 test_b99 

我怎样才能做到正确的结果?

回答

0
sort -k2,2.7 

结果

0.1 test_a21 
0.2 test_a1 
0.3 test_a1 
0.4 test_a1 
0.5 test_a21 
0.9 test_a21 
0.2 test_b99 
0.3 test_b99