ar.dll
ar.dll

Reputation: 787

awk sum numbers after a separator

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

Answers (1)

shellter
shellter

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

Related Questions