Awk, if line after string does not match insert

I have a large file with interface records. I need to check every record that has the string "encapsulation bridge1483" and if the next line after this does not have "ip description" then I need to insert a line to add "ip description blah_blah_blah.

Sample file:

interface atm 1/0.190158 point-to-point
 atm pvc 100190158 19 158 aal5snap 768 768 10
 encapsulation pppoe
! 
interface atm 1/0.190158.1
 encapsulation ppp
 ppp authentication pap
 profile any "prof-pppoe"
! 
interface atm 1/0.20203 point-to-point
 atm pvc 100020203 2 203 aal5snap 1500 1500 10
 encapsulation bridge1483
 ip address 10.132.1.1 255.255.255.248
!
interface atm 1/0.80180 point-to-point
 atm pvc 100080180 8 180 aal5snap 3000 3000 10
 encapsulation bridge1483
 ip description won_ton_soup_company
 ip address 10.42.3.1 255.255.255.248
!
interface atm 1/0.100115 point-to-point
 atm pvc 100100115 10 115 aal5snap 6000 6000 10
 encapsulation bridge1483
 ip description dickandjanes
 ip address 10.2.3.1 255.255.255.248
!

What I need to have output:

interface atm 1/0.190158 point-to-point
 atm pvc 100190158 19 158 aal5snap 768 768 10
 encapsulation pppoe
! 
interface atm 1/0.190158.1
 encapsulation ppp
 ppp authentication pap
 profile any "prof-pppoe"
! 
interface atm 1/0.20203 point-to-point
 atm pvc 100020203 2 203 aal5snap 1500 1500 10
 encapsulation bridge1483
ip description blah_blah_blah
 ip address 10.132.1.1 255.255.255.248
!
interface atm 1/0.80180 point-to-point
 atm pvc 100080180 8 180 aal5snap 3000 3000 10
 encapsulation bridge1483
 ip description won_ton_soup_company
 ip address 10.42.3.1 255.255.255.248
!
interface atm 1/0.100115 point-to-point
 atm pvc 100100115 10 115 aal5snap 6000 6000 10
 encapsulation bridge1483
 ip description dickandjanes
 ip address 10.2.3.1 255.255.255.248
!

Try

$ awk '/encapsulation bridge1483/{print;getline;if($0!~/ip description/)print "ip description blah_blah_blah"}1'  file
interface atm 1/0.190158 point-to-point
 atm pvc 100190158 19 158 aal5snap 768 768 10
 encapsulation pppoe
! 
interface atm 1/0.190158.1
 encapsulation ppp
 ppp authentication pap
 profile any "prof-pppoe"
! 
interface atm 1/0.20203 point-to-point
 atm pvc 100020203 2 203 aal5snap 1500 1500 10
 encapsulation bridge1483
ip description blah_blah_blah
 ip address 10.132.1.1 255.255.255.248
!
interface atm 1/0.80180 point-to-point
 atm pvc 100080180 8 180 aal5snap 3000 3000 10
 encapsulation bridge1483
 ip description won_ton_soup_company
 ip address 10.42.3.1 255.255.255.248
!
interface atm 1/0.100115 point-to-point
 atm pvc 100100115 10 115 aal5snap 6000 6000 10
 encapsulation bridge1483
 ip description dickandjanes
 ip address 10.2.3.1 255.255.255.248
!
1 Like
awk '{y=x;x=$0}y~/bridge1483/&&x!~/description/{print " ip description blabla..."}1' infile
1 Like

Perfect! Thank you!