Skip to content
Advertisement

Arithmetic in Shell script

After executing this

ta=`zcat abc.log.2019071814.gz |grep "R_MT"|grep "A:1234"|grep "ID:413"|awk -F"|" '{print $20}'|sort|uniq -c|awk '{$1=$1};1'`

Here $20 indicates the “S:” entry in each row (I am taking the unique count of all s values),I am getting result as

93070 S:1 11666 S:8 230 S:9

so what I need is the sum of all occurrence of s values .i.e 93070+11666+230 so result be total=104966

Advertisement

Answer

$ echo 93070 S:1 11666 S:8 230 S:9 | sed -E 's,S:[0-9]+,,g' | sed 's,  ,+,g'  | bc -
104966
Advertisement