shell - Look up and sort data from some .txt files -


i dealing following problem:

i have extract data set of .txt files. files distributed in different directories using next command:

find -name results.txt | xargs grep "gion_prom=" 

it looks keyword gion_prom= inside results.txt files , returns this:

./40/r4_cero_cluster/thermo/results.txt: gion_prom= -67555.5392  ./50/p1_water_cero/thermo/results.txt: gion_prom= -73379.3272  ./50/r4_cero_cluster/thermo/results.txt: gion_prom= -67680.5744  ./5/p1_water_cero/thermo/results.txt: gion_prom= -73778.5554  ./5/r4_cero_cluster/thermo/results.txt: gion_prom= -68058.3461  ./60/p1_water_cero/thermo/results.txt: gion_prom= -73488.4344  ./60/r4_cero_cluster/thermo/results.txt: gion_prom= -67944.0657  

it works good, need need onyl files keyword "r4_cero_cluster" printed, should looks this:

./40/r4_cero_cluster/thermo/results.txt: gion_prom= -67555.5392  ./50/r4_cero_cluster/thermo/results.txt: gion_prom= -67680.5744  ./5/r4_cero_cluster/thermo/results.txt: gion_prom= -68058.3461  ./60/r4_cero_cluster/thermo/results.txt: gion_prom= -67944.0657  

then, if possible, need sort number "40", "50", "60", , on. so, final data printed in terminal should be:

./5/r4_cero_cluster/thermo/results.txt: gion_prom= -68058.3461      ./40/r4_cero_cluster/thermo/results.txt: gion_prom= -67555.5392  ./50/r4_cero_cluster/thermo/results.txt: gion_prom= -67680.5744  ./60/r4_cero_cluster/thermo/results.txt: gion_prom= -67944.0657  

i know last thing maybe sort function used beginner programming , don't know how that.

any or advice welcome.

edit

the keyword find search results.txt files. when doing ´grep´ searches keyword ´gion_prom´ inside results.txt files.

i need printed ´gion_prom´ files in parent directory ´r4_cero_cluster´ to avoid results coming ´r4_cero_cluster´ directories..

you can use -path option in find find files in matching path , pipeline sort after grep:

find . -path '*/r4_cero_cluster/*' -name results.txt | xargs grep 'gion_prom=' | sort -t/ -k2,2n 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -