I have a log file from a web server which looks like this;
1908 462
232 538
232 520
232 517
My task is to total column 1 and column 2 in a bash script. My desired output is;
2604 2037
I know of awk or sed which could go a long way to solving my problem but I can’t fathom how to actually do it. I’ve trawled examples on Google but haven’t turned up anything useful. Can someone point me in the right direction please?
(Note the complete lack of error checking.)
EDIT :
Ok, here’s a version with error checking:
If you don’t want to accept leading or trailing blanks, delete the two
" *"s in the if statement.But this is big enough that it probably shouldn’t be a one-liner:
There’s still no overflow or underflow checking, and it assumes that there will be no signs. The latter is easy enough to fix; the former would be more difficult. (Note that awk uses floating-point internally; if the sum is big enough, it could quietly lose precision.)