I have the following file:
lab1:/etc/scripts# cat /tmp/tmp.PGikhA/audit.txt
344 server1
1 server2
I want to be able to add the numbers from each row together - so in this case, I want to add 344 + 1 and end up with 345.
So far, I have the following steps figured out:
lab-1:/etc/scripts# cat /tmp/tmp.PGikhA/audit.txt |awk '{print $1}'
344
1
But I don't know how to add them together. I know that I can just use $a + $b syntax, but how do I get the 344 and 1 into separate variables to do that?
Thanks.
EDIT 1
I'm getting two values returned instead of just the one total. Can't see what I'm doing wrong:
lab-1:/etc/scripts# cat /tmp/tmp.jcbiih/audit.txt | awk '{print $1}' | awk '{ sum+=$1} {print
sum}'
344
345
lab-1:/etc/scripts# cat /tmp/tmp.jcbiih/audit.txt | awk '{ sum+=$1} {print sum}'
344
345
355
a typo?