 <p>Kind of standard <code>awk</code> way.</p> <pre><code>$ awk 'FNR==NR{sum+=$2;next}; {print $0,sum}' file.txt{,} 1 12 272 2 18 272 3 45 272 4 5 272 5 71 272 6 96 272 7 13 272 8 12 272 </code></pre>