Linking back to my previous question, I found the problem not to be entirely solved. Here's the problem:
I have directories named RUN1
, RUN2
, and RUN3
Each directory has some files. Directory RUN1
has files mod1_1.csv
, mod1_2.csv
, mod1_3.csv
. Directory RUN2
has files mod2_1.csv
, mod2_2.csv
, mod3_3.csv
, etc.
The contents of mod1_1.csv
file look like this:
5.71 6.66 5.52 6.90
5.78 6.69 5.55 6.98
5.77 6.63 5.73 6.91
And mod1_2.csv
looks like this:
5.73 6.43 5.76 6.57
5.79 6.20 5.10 7.01
5.71 6.21 5.34 6.81
In RUN2, mod2_1.csv looks like this:
5.72 6.29 5.39 5.59
5.71 6.10 5.10 7.34
5.70 6.23 5.23 6.45
And mod2_2.csv looks like this:
5.72 6.29 5.39 5.69
5.71 6.10 5.10 7.32
5.70 6.23 5.23 6.21
My goal is to obtain the line with the smallest value of column 4 for each RUN* directory, and write that and the model which gave it to a new .csv file. Right now, I have this code:
#!/bin/bash
resultfile="best_results_mlp_2.txt"
for d in $(find . -type d -name 'RUN*' | sort);
do
find $d -type f -name 'mod*' -exec sort -k4 {} -g \; | head -1 >> "$resultfile"
done
But it doesn't always return the smallest value of column 4 (I went through the files and checked), and it doesn't include the file name that contains the smallest number. To clarify, I would like a .csv file with these contents:
5.73 6.43 5.76 6.57 mod1_2.csv
5.72 6.29 5.39 5.59 mod2_1.csv