0

我想计算像 ix1 这样的接口的数据包。netstat -I ix1 -w1 的结果是这样的。

  input          (ix1)           output

数据包错误 idrops 字节数据包错误字节 colls

     0     0     0          0          0     0          0     0

1042563 0 0 794182232 0 0 0 0

1537437 0 0 1177837768 0 0 0 0

     0     0     0          0          0     0          0     0

谁可以得到第一列的总和?我试过 grep 但它不方便请你帮忙怎么做?用 grep 或 cut 或 ....?

4

1 回答 1

0

我用 awk 找到了答案。这就是答案。$1 是您想要的列

netstat -I ix1 -w1 | awk ' { print s } { s += $1}'

使用此命令,您可以拥有超过 1 列

netstat -I ix1 -w1 | awk ' { print "input: "s"    output: "ss } { s += $1}  { ss += $5}'
于 2015-08-24T10:21:04.747 回答