Wednesday 14 February 2018

bash - sum numbers in different lines in shell


i have 8000 lines similar to this


 

and what i need to do is summing rxPackets in each line together and txPackets too


i mean total sum of them in 8000 lines


thanks in advance








Answer



You can use this small awk script for GNU awk:


awk 'BEGIN {x=0;y=0} { match($13,/([0-9]+)/,a); x = x + a[1]; match($12,/([0-9]+)/,b); y = y + b[1]} END {print "rxPackets:" x " txPackets:" y}' yourfile

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...