I know how to pass variables to awk, but I haven't been able to combine that with the column number functionality when working with a CSV. I'm also not sure how to perform a string concatenation this way.
I'm expecting some columns in my CSVs to contain dates in MM-dd-yyyy or yyyy/MM/dd format, or some permutation of those, and would like to append a default hh:mm:ss onto it, so a column of 1/10/2017 becomes 1/10/2017 00:00:00. I've tried doing something along these lines in awk, but it doesn't seem to recognize the column I'm trying to reference. And I don't think this is how string concatenation is done.
for file in *.csv; do
headline=$(head -n 1 $file)
byline=$(sed '2q;d' $file)
IFS=', ' read -r -a headers <<< $headline
IFS=', ' read -r -a entries <<< $byline
for i in "${!headers[@]}"; do
date='^[0-9]+[/-][0-9]+[/-][0-9]+$'
if [[ ${entries[$i]} =~ $date ]] ; then
awk -F, -v col='$i' '{$($col)+="00:00:00";}1' OFS=, $file
fi
done
done