0

I have two files ...

First file(input 1):

1: 6.1703
44 14.7262
46 18.3255

2: 6.1932
44 52.9379
46 4.30653

3: 6.5664
45 2.82839
46 3.1275

4: 8.0923
44 14.1076

Second file(input 2):

43          5e-05           4e-05
44          1e-05           2e-05
45          0.00083         1.00083
46          4e-05           7e-05
47          0.00021         6.00021

... and I want to multiply the elements of the first file with the two elements of the second file, taking in consideration the number located in the first column(both files). The output should look like this:

1: 6.1703
44 14.7262*1e-05   14.7262*2e-05    
46 18.3255*4e-05   18.3255*7e-05

2: 6.1932
44 52.9379*1e-05   52.9379*2e-05
46 4.30653*4e-05   4.30653*7e-05

3: 6.5664
45 2.82839*0.00083 2.82839*1.00083
46 3.1275*4e-05    3.1275*7e-05

4: 8.0923
44 14.1076**1e-05  14.1076**2e-05
1

Slurp columns 2 and 3 from file2 into arrays a and b keyed by column 1. Loop through and print from file1 using array members from a and b as multipliers and column 2 values as multiplicands

awk 'NR == FNR{a[$1]=$2; b[$1]=$3; next}
     /:/ || !NF{print; next}
     {print $1, $2*a[$1], $2*b[$1]}' file2 file1

1: 6.1703
44 0.000147262 0.000294524
46 0.00073302 0.00128279

2: 6.1932
44 0.000529379 0.00105876
46 0.000172261 0.000301457

3: 6.5664
45 0.00234756 2.83074
46 0.0001251 0.000218925

4: 8.0923
44 0.000141076 0.000282152

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.