Reputation: 1
Good afternoon, I'm trying to do the following multiplication with awk:
0 1 2 3
2 A21*A12 A21*A13 A21*A14
5 A31*A12 A31*A13 A31*A14
4 A41*A12 A41*A13 A41*A14
Input:
0 1 2 3
2
1
3
Expected output:
0 1 2 3
2 2 4 6
1 1 2 3
3 3 6 9
Is it possible to do this using awk?
Upvotes: 0
Views: 77
Reputation: 247012
awk '
NR == 1 {n = split($0, a)}
NR > 1 {for (i=2; i<=n; i++) $i = a[i] * $1}
{print}
' input
0 1 2 3
2 2 4 6
1 1 2 3
3 3 6 9
Upvotes: 3