I have the following program that allows me to move a file (actually a table) if the value of the first line of the fourth column is the highest one (in comparison with 8 other files having the same naming style. Here is the script:
#! /bin/bash
river=mississippi
highest=1
for model in H08 MPI-HM WBM PCR-GLOBWB
do
for gcm in GFDL-ESM2M HadGEM2-ES IPSL-CM5A-LR MIROC-ESM-CHEM NorESM1-M
do
for scenario in hist rcp8p5 rcp4p5
do
RESULT=$(awk 'FNR==1 {print $4, FILENAME}' ${model}_${gcm}_${scenario}_${river}[1-9]/${model}_${gcm}_${scenario}_${river}[1-9].txt | sort -n -r| head -1)
highest="$(echo $RESULT | cut -d ' ' -f1 )"
hifile="$(echo $RESULT | cut -d ' ' -f2 )"
echo "highest was $highest in $hifile"
cp "$hifile" "/home/stevens/SUMARIO/Fred/highest_discharge/${river}/${model}_${gcm}_${scenario}_${river}.txt"
done
done
done
Then, I would like to adapt this script in such a way that instead of copying the file having the highest value (in first row, fourth column), I would like to copying the file having the highest average value at the fourth column, in comparison with the other files. Any hints or advice is greatly appreciated!