Hey all,
I'm having some trouble figuring out how to escape variables inside a bash
for loop used as field names in awk.
Here is the basic idea: get the max value from each column in a csv file
with a number of columns less than 100. This is what I have tried so far:
sed -i 's/,/ /g' ./file.csv
for fieldnum in {1..100}
do
awk '{if(min==""){min=max=$$fieldnum}; if($$fieldnum>max)
{max=$$fieldnum};} END {print max}' ./file.csv
done
I have tried escaping the $ and $fieldnum with backslash, parentheses,
quotes, I can't use single quotes, as that is what awk uses for it's
expressions, and every way I have tried that doesn't give a syntax error
just prints the entire line $fieldnum times. Is there a way to do this, or
should I look for a tool other than awk? I wouldn't be opposed to using a
different shell, although I only have experience with bash and a smidgen
with korn.
Thanks!
Marshall