由于错误,我无法运行此代码
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
问题是“,a”和“,b”将数字放入数组a中
输入是这样的几行:
<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">
输出将分别得到 rxPackets 和 txPackets 的总和(例如 100 行),但它会给出错误
我需要以任何可能的方式做到这一点谢谢
答案1
尝试分别运行两个命令,如下所示:
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}'