0

I want to count the packets of an interface like ix1 . The result of netstat -I ix1 -w1 is something like this .

  input          (ix1)           output

packets errs idrops bytes packets errs bytes 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

who can I get sum of the fist column ? I tried with grep but it is not handy would you please help how to do it ? with grep or cut or ....?

sam
  • 1,363
  • 1
  • 20
  • 32

1 Answers1

0

I found my answer with awk . this is the answer . $1 is the column you want

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

and with this command you can have more than 1 Column

netstat -I ix1 -w1 | awk ' { print "input: "s"    output: "ss } { s += $1}  { ss += $5}'
Paul R
  • 208,748
  • 37
  • 389
  • 560
sam
  • 1,363
  • 1
  • 20
  • 32