Reputation: 787
I need a simple awk to calculate the sum of the number at the end of a file which looks like this:
/z02/ABCD/stuff/ABC_DEF_02/count/ABC_DEF_02_ABCDE66.log.20120605_101201_015.log.gz:28
/z02/ABCD/stuff/ABC_DEF_02/count/ABC_DEF_02_ABCDE66.log.20120605_101202_015.log.gz:28
/z02/ABCD/stuff/ABC_DEF_02/count/ABC_DEF_02_ABCDE66.log.20120605_101203_015.log.gz:28
/z02/ABCD/stuff/ABC_DEF_02/count/ABC_DEF_02_ABCDE66.log.20120605_101204_015.log.gz:28
so basically the numbers after the ":" need to be added together
Upvotes: 1
Views: 235
Reputation: 37298
echo "....." | awk '-F:' '{total+=$NF}END{print "sumTotal=" total}'
You can, of course, leave out the "sumTotal=" part, depending on your needs.
I hope this helps.
Upvotes: 4