How to sort the file names in bash in this circumstance?

Posted by Nicolas on Stack Overflow See other posts from Stack Overflow or by Nicolas
Published on 2014-06-13T02:27:23Z Indexed on 2014/06/13 3:25 UTC
Read the original article Hit count: 375

Filed under:

I have run a program to generate some results with the different parameters(i.e. the R, C and RP). These results are saved in files named results.txt. Then, I should parse these experimental results to make an analysis. In the params_R_7_C_16_RP_0, the 7 is the value of the parameter R, the 16 is the value of the parameter C and the 0 is the value of the parameter RP.

Now, I want to get these results.txt files in the current directory to parse, and sort the path with the parameter values of R,C and RP.

I first use the following command to get the results.txt files that I want to parse:

find ./ -name "results.txt"

and the output is:

./params_R_11_C_9_RP_0/results.txt 
./params_R_7_C_9_RP_0/results.txt
./params_R_7_C_4_RP_0/results.txt
./params_R_11_C_16_RP_0/results.txt 
./params_R_9_C_4_RP_0/results.txt
./params_R_5_C_9_RP_0/results.txt 
./params_R_9_C_25_RP_0/results.txt 
./params_R_7_C_16_RP_0/results.txt 
./params_R_5_C_25_RP_0/results.txt 
./params_R_5_C_16_RP_0/results.txt 
./params_R_11_C_4_RP_0/results.txt
./params_R_9_C_16_RP_0/results.txt
./params_R_7_C_25_RP_0/results.txt
./params_R_15_C_4_RP_0/results.txt 
./params_R_5_C_4_RP_0/results.txt 
./params_R_9_C_9_RP_0/results.txt 

and I change the command as follows:

find ./ -name "results.txt" | sort

and the output is:

./params_R_11_C_16_RP_0/results.txt
./params_R_11_C_25_RP_0/results.txt
./params_R_11_C_4_RP_0/results.txt
./params_R_11_C_9_RP_0/results.txt
./params_R_5_C_16_RP_0/results.txt
./params_R_5_C_25_RP_0/results.txt
./params_R_5_C_4_RP_0/results.txt
./params_R_5_C_9_RP_0/results.txt
./params_R_7_C_16_RP_0/results.txt
./params_R_7_C_25_RP_0/results.txt
./params_R_7_C_4_RP_0/results.txt
./params_R_7_C_9_RP_0/results.txt
./params_R_9_C_16_RP_0/results.txt
./params_R_9_C_25_RP_0/results.txt
./params_R_9_C_4_RP_0/results.txt
./params_R_9_C_9_RP_0/results.txt

But I want it output as following:

./params_R_5_C_4_RP_0/results.txt
./params_R_5_C_9_RP_0/results.txt
./params_R_5_C_16_RP_0/results.txt
./params_R_5_C_25_RP_0/results.txt
./params_R_7_C_4_RP_0/results.txt
./params_R_7_C_9_RP_0/results.txt
./params_R_7_C_16_RP_0/results.txt
./params_R_7_C_25_RP_0/results.txt
./params_R_9_C_4_RP_0/results.txt
./params_R_9_C_9_RP_0/results.txt
./params_R_9_C_16_RP_0/results.txt
./params_R_9_C_25_RP_0/results.txt
...

I should let it params_R_005_C_004_RP_0 when generating the results. But it would take much time to rerun the program to get the results. So I wonder if there is any way to use the bash command to achieve this objective.

© Stack Overflow or respective owner

Related posts about bash