Sum values of specific columns using awk
<p>So I have a file which looks like this:</p>

<pre><code>1 4 6 
2 5
3
</code></pre>

<p>I want to sum only specific columns, let's say the first and third.
And the output should look like this:</p>

<pre><code>7
2
3
</code></pre>

<p>I store numbers of columns (arguments) in a variable:
<strong><code>x=${@:2}</code></strong> (because I omit first passed argument which is a <strong><code>$filename</code></strong>)</p>

<p>How to calclute this using awk in a bash script ?
I was thinking about sth like this                                                            </p>

<pre><code>for i in ${@:2}
do
    awk  -v c=$i '{sum+=$c;print sum}' $fname

done
</code></pre>

<p>But it does not work properly.</p>