AWK does not work correctly in my system

1

i cant run this code because of an error

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

the problem is ",a" and ",b" that put numbers in array a

input is some lines like this:

<Flow flowId="1" timeFirstTxPacket="+0.0ns" timeFirstRxPacket="+924100.0ns" timeLastTxPacket="+199984927558.0ns" timeLastRxPacket="+199675473275.0ns" delaySum="+2287566662167.0ns" jitterSum="+65280162191.0ns" lastDelay="+3511349483.0ns" txBytes="161956" rxBytes="116536" txPackets="3125" rxPackets="2251" lostPackets="640" timesForwarded="0">

and output will get me sum of rxPackets and txPackets seperatly in for example 100 lines but it will give me error

i need to do this in any way possible thanks

Arash

Posted 2013-12-12T14:51:23.357

Reputation: 678

Question was closed 2013-12-12T15:32:56.877

I suggest bailing out before writing one more line of AWK and use a modern scripting language such as Python. – kmarsh – 2013-12-12T14:54:12.520

What error are you getting? Are you certain that all lines are formatted correctly? Are you using GNU awk, or a different one (if you don't know: are you runing this on Linux (what distribution? embeddable ones are different), cygwin, or something else? – Gabe – 2013-12-12T15:06:57.230

@Gabe ubuntu 13.04 MAWK(1) – Arash – 2013-12-12T15:07:41.660

... and again, what is the error you're seeing? I do not understand what you mean with "the problem is ",a" and ",b" that put numbers in array a". – Gabe – 2013-12-12T15:12:49.527

Please see my revised post. – MariusMatutiae – 2013-12-12T15:18:05.403

Please post one question about the problem you're trying to solve – this is something you should've edited your old question with and talked about with the user who answered, if the syntax didn't work. – slhck – 2013-12-12T15:35:04.130

Answers

2

Try running two commands separately, like this:

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

MariusMatutiae

Posted 2013-12-12T14:51:23.357

Reputation: 41 321

the problem still there awk: line 1: syntax error at or near , :( – Arash – 2013-12-12T15:05:03.533