I want to shift away from Excel to Awk. I need basic mathematical operations, such as addition and division, for arrays.
For example, arrays A and B are [1, 3, 2] and [2, 1, 2], respectively. How can I get an array [2, 3, 4] from the multiplication between A and B? What about the addition and division between A and B?
I think awk is not done for this sort of numeric work. It’s more for text processing. Arrays in awk are associative and sparsely occupied (may have ‘holes’ between its indexes). You use strings to index them:
It’s like a hash-map. So, in awk you can do
And have only 2 elements stored in that array (elements from 2 to 99 do not exist), indexed by strings that are created by converting the numbers 100 and 1. The GNU Awk manual has a nice section about arrays in awk here.