#! /bin/bash # make a function to get the filename without path or extension function get_name() { local base=${1##*/} local base0="${base%.*}" local base1="${base0%.*}" echo $base1 } echo "#FILE,METHOD,ESTIMATE,ACTUAL" ActualsFile="../MyActuals.csv" cd Estimates for x in * do estimate=$(cat $x | gawk 'BEGIN{FS=" "}NR==1{print $5}') file=$(get_name $x | gawk 'BEGIN{FS="-";OFS=","}{print $1}') method=$(get_name $x | gawk 'BEGIN{FS="-";OFS="-"}{print $2,$3,$4,$5}') #actual=$file actual=$(gawk -v file=$file 'BEGIN{FS=OFS=","}{if ($1==file) {print $2}}' $ActualsFile) echo $file","$method","$estimate","$actual done