awk - How to edit a Unix file to insert a few lines after 2 specific pattern matches -


i have file content below. want edit file whenever in file ltpgy pattern seen after line "set t table new $m table]", insert new line content "found".

the input file follows :-

  set ra [ 1 22 3 ] ltpgy   set 0   set a1 1    set t [ table new $m table]   set [  $t process_axis]   set [  $t voltage_axis]      set ra [ 1 22 3 ] stpgy   set 0   set a1 1    set t [ table new $m table]   set [  $t process_axis]   set [  $t voltage_axis]     set ra [ 1 22 3 ] ltpgy   set 0   set a1 1    set t [ table new $m table]   set [  $t process_axis]   set [  $t voltage_axis]      set ra [ 1 22 3 ] stpgy   set 0   set a1 1    set t [ table new $m table]   set [  $t process_axis]   set [  $t voltage_axis] 

i want output :-

  set ra [ 1 22 3 ] ltpgy   set 0   set a1 1    set t [ table new $m table]   found   set [  $t process_axis]   set [  $t voltage_axis]      set ra [ 1 22 3 ] stpgy   set 0   set a1 1    set t [ table new $m table]   set [  $t process_axis]   set [  $t voltage_axis]     set ra [ 1 22 3 ] ltpgy   set 0   set a1 1    set t [ table new $m table]   found   set [  $t process_axis]   set [  $t voltage_axis]      set ra [ 1 22 3 ] stpgy   set 0   set a1 1    set t [ table new $m table]   set [  $t process_axis]   set [  $t voltage_axis] 

works gawk, untested on other awks:

gawk '     /set ra / {found = /ltpgy/}     1;     index($0, "set t [ table new $m table]") && found {print "found"} ' file 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -