I'm trying to divide all lines in file1.txt by their respective (column-wise) value in the single line in file2.txt.
cat file1.txt
1 2.5 3
7 7 7
1 3 5
cat file2.txt
1 3 5
Following the suggested solution for this question: https://stackoverflow.com/questions/44908195/awk-multiplication-of-all-rows-in-a-table-with-first-row-of-the-table, I came up with the following code:
cat file2.txt file1.txt | awk 'NR==1{split($0,m);CONVFMT="%.5f\t";next} {for (i=1;i<=NF;i++) $i=$i/m[i]} 1'
However, since all values in one of the rows equal 1, and CONVFMT doesn't work on integers, the format in my output file is messed up. To fix this, I was thinking on using printf with tab separator instead of CONVFMT, but given that my actual files have a variable number of columns, I don't want a hard coded solution using $1, $2, etc. I'm not proficient in awk so I can't quite come up with a fix on my own.
Thank you very much in advance for your help!
Edit: all numbers in output should be formatted as %.5f.