Sum each element of a row from two files
<p>I want to write shell script in which each row's column element from file1 and file2 are added.</p>

<p><code>file1</code>:</p>

<pre><code>A 10 12 13 14
B 2 5 6 10
C 1
</code></pre>

<p><code>file2</code>:</p>

<pre><code>A 11 13 11 15
B 3 1 1 1
C 2
</code></pre>

<p><code>output</code>:</p>

<pre><code>A 22 25 24 29
B 5 6 7 11
C 3
</code></pre>

<p>I have tried to write this, but it seems very chaotic.
So I'd like to get some help to make it better!</p>

<pre><code>awk '{getline v &lt; "file1"; split( v, a ); 
        for (i = 2; i &lt;= NF; i++) 
            {print a[1], a[i]+ $i}
        }' file2 &gt; temp

awk '{a[$1]=a[$1]" "$2}
    END{for(i in a)print i,a[i]
    }' temp &gt; out
</code></pre>