按第2列的子字符串排序,然后按第1列bash排序

按第2列的子字符串排序,然后按第1列bash排序,bash,shell,Bash,Shell,我的文件如下所示: 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列,末尾没有数字(在上例中,两组为测试a和测试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 tes

我的文件如下所示:

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列,末尾没有数字(在上例中,两组为测试a和测试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
如何获得正确的结果?

sort-k2,2.7
结果

0.1测试\u a21
0.2测试单元a1
0.3测试单元a1
0.4测试单元a1
0.5测试_a21
0.9测试_a21
0.2测试单元b99
0.3测试单元b99