Hello,
I have some code that searches file names, sorts them on a field in the name, and returns the top value.
# list the contents, strip off the path, and sort on field 3 as a number, returns top value
TOP_OUTCOME=$(ls './'$SET_F'/'$FOLD'/'$FOLD'_anneal/'$C_PARAMS'/'$A_SET'/'*'out.txt' | \
awk 'BEGIN {FS="/"} {print $7}' | \
sort -t_ -k 3 -n | \
head -n 1)
The file names look like,
V_se_69.36_E1_f5_r09_1-ON-0.25_S3C_v1_36.35.1.out.txt
V_se_69.62_E195_f5_r17_195-ON-0.25_S3C_v1_36.35.1.out.txt
V_se_70.14_E254_f5_r06_254-ON-0.25_S3C_v1_36.35.1.out.txt
V_se_70.41_E230_f5_r08_230-ON-0.25_S3C_v1_36.35.1.out.txt
V_se_71.00_E150_f5_r42_150-ON-0.25_S3C_v1_36.35.1.out.txt
The code sorts on the real in the third underscore delimited field. There are circumstances where I may not actually want the top value, but I need to read the file name to find out. In this case, since the value of the 4th field is E1 (the 1 is the important thing), I would want to look at the next value.
I guess I could collect the top 10 or so and loop though the file names, but I was also considering something like grabbing the top value as above, testing a filed (I will want the top value 99% of the time so most will pass the test), and then grabbing the 2nd value in the event of a fail, testing that name, etc.
It seems like grabbing a bunch,
TOP_OUTCOME=$(ls './'$SET_F'/'$FOLD'/'$FOLD'_anneal/'$C_PARAMS'/'$A_SET'/'*'out.txt' | \
awk 'BEGIN {FS="/"} {print $7}' | \
sort -t_ -k 3 -n | \
head -n 10)
and testing fields in a while loop would be the most efficient method, but I thought I would check. There are times where I would need to use tail instead of head with the same code, so that complicates things some I guess.
LMHmedchem