Check numeric fields greater than zero, and delete lines if appropriate

This be the latest in my problems sorting through router logs... I'm half way there on a problem, but I've hit the limitation of my knowledge

Got some router interface log files of type

router01:GigabitEthernet9/24 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 0 frame, 19 overrun, 0 ignored
router01:GigabitEthernet10/1 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 5 frame, 0 overrun, 0 ignored
router01:GigabitEthernet10/2 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 3 frame, 0 overrun, 0 ignored
router01:GigabitEthernet10/5 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 2 frame, 0 overrun, 0 ignored
router01:GigabitEthernet10/6 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 2 frame, 0 overrun, 0 ignored
router01:GigabitEthernet10/9 is up, line protocol is up (connected)
router01: 6297 input errors, 6297 CRC, 6298 frame, 0 overrun, 0 ignored
router01:GigabitEthernet10/10 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 1 frame, 0 overrun, 0 ignored
router01:GigabitEthernet10/14 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 1 frame, 0 overrun, 0 ignored

I don't care about frame errors or ignored errors, but I do want to take account of input errors, CRC errors and overrun errors, so I want to keep those lines (and the line above them) where those parameters are non zero, and I want to delete those lines where the important parameters are 0, and the lines above them. So... for the input above... I want the output to be

router01:GigabitEthernet9/24 is up, line protocol is up (connected)
router01: 0 input errors, 0 CRC, 0 frame, 19 overrun, 0 ignored
router01:GigabitEthernet10/9 is up, line protocol is up (connected)
router01: 6297 input errors, 6297 CRC, 6298 frame, 0 overrun, 0 ignored

I'm thinking the way to do it is to sort for lines with the string "input errors", and check if the second, or fifth, or ninth parameters are non zero, and if so keep that line and the line above it, otherwise delete the line and the line above it.

I'm doing this on ubuntu... (may or may not be relevant)

One way:

awk '/input errors/ && ($2 + $5 + $9) > 0 {print s; print}{s=$0}' logfile

On the contrary, it's quite relevant:

grep -EB1 '[^0] (CRC|overrun)' infile

Thanks Franklin and radoulov

Both solutions work... but with a proviso... the log file contains similar lines but with the other types of errors seen on Cisco interfaces as well... and all these lines are deleted also. I just want to delete the lines I mentioned...

I'm guessing both solutions use a sort of 'delete everything else'. I just want 'delete line n and line n-1'

---------- Post updated at 07:08 AM ---------- Previous update was at 06:28 AM ----------

Since there's a start and end pattern to the section I want this to work on... I was thinking I might be able to nest awk's...

ie

awk '/start pattern/,/end pattern/ { awk '/input errors/ && ($2 + $5 + $9) > 0 {print s; print}{s=$0} }' infile 

doesn't work though... I'm getting this error

bash: syntax error near unexpected token `{print'

Whats the correct syntax for this?

might be somethng like this :

awk '/start pattern/,/end pattern/ ' infile | awk '/input errors/ && ($2 + $5 + $9) > 0 {print s; print}{s=$0} ' 

[/FONT]

This one?

perl -ne'
  $p = $_ and next if /line protocol/;
  $s = $_ and s/^[^:]+:\s*|\d+\s+(frame|ignored),?//g;
  print $p, $s if grep /[^0]/, @{[/(\d)/g]}
  ' infile

Something like this?

awk '/start pattern/{p=1} /end pattern/{p=0}
p && /input errors/ && ($2 + $5 + $9) > 0 {print s; print}{s=$0}' file

Nearly there...

Panyam: That works alright... but its only outputting the results of the section I'm working on, the rest of the file is lost... trying to think if there's a way to leave the rest of the file through untouched.

Radoulov: That works too... it even leaves the contents of the rest of the file... but removes the start and stop pattern from the file that helps see whats going on. The start of each section has a line containing the word 'section'. I've tried including in your script via the following

perl -ne'
  $a = $_ if /section/;
  $p = $_ and next if /line protocol/;
  $s = $_ and s/^[^:]+:\s*|\d+\s+(frame|ignored),?//g;
  print $a, $p, $s if grep /[^0]/, @{[/(\d)/g]}
  ' infile

but it doesn't work. Prints the section delimiter between every interface

---------- Post updated at 08:02 AM ---------- Previous update was at 07:32 AM ----------

Minor miracle... figured it out....

perl -ne'
  $a = $_ if /section/;
  $p = $_ and next if /line protocol/;
  $s = $_ and s/^[^:]+:\s*|\d+\s+(frame|ignored),?//g;
  print $a if grep /section/, @{[$_]};
  print $p, $s if grep /[^0]/, @{[/(\d)/g]}
  ' infile

Thanks for all the suggestions...