简体   繁体   中英

Can Linux Sort sort mixed value columns?

I have a program that outputs something like this:

0: test_func()   4x1024     0.2260167
0: test_func()    4x128     0.020995
0: test_func()   4x2048     0.330319
0: test_func()    4x256     0.024929
0: test_func()   4x4096     1.329865
0: test_func()    4x512     0.056119
0: test_func()     4x64     0.004869
0: test_func()   4x8192     3.288312
0: test_func()  16x1024     0.778160
0: test_func()   16x128     0.084252
0: test_func()  16x2048     1.671658
0: test_func()   16x256     0.190282
0: test_func()  16x4096     5.664730
0: test_func()   16x512     0.312114
0: test_func()    16x64     0.036087
0: test_func()  16x8192    12.404933
1: test_func2()    4x64     0.004869

I want to sort by the third column so that the output looks like this:

0: test_func()     4x64     0.004869
0: test_func()    4x128     0.020995
0: test_func()    4x256     0.024929
0: test_func()    4x512     0.056119
0: test_func()   4x1024     0.226016
0: test_func()   4x2048     0.330319
0: test_func()   4x4096     1.329865
0: test_func()   4x8192     3.288312
0: test_func()    16x64     0.036087
0: test_func()   16x128     0.084252
0: test_func()   16x256     0.190282
0: test_func()   16x512     0.312114
0: test_func()  16x1024     0.778160
0: test_func()  16x2048     1.671658
0: test_func()  16x4096     5.664730
0: test_func()  16x8192    12.404933
1: test_func2()    4x64     0.004869

Is there a way to sort the third column so it will first sort by the first dimension in increasing order, then the second dimension in increasing order? Incidentally the sort command I am using right now to get the results I am getting so far is:

sort -k2,2 -k1,1n -k3,3n

This should work for you

sort -tx -k1,1r file

I'm using x as the field delimiter


PS: It does just work because 0: and test_func() appears on every line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM