vendredi 24 juin 2016

awk to print from last match of start match pattern till end pattern

I have a file with contents like this.

if {[CELL NAME "CELL1"]} {
define_cell \
       -pinlist { i0 i1 i2 0 } \
       CELL1
}
if {[CELL NAME "CELL2"]} {
define_cell \
       -pinlist { i0 i1 i2 0 } \
       CELL2
}
define_cell \
       -pinlist { i0 i1 i2 0 } \
       CELL3  
define_cell \
       -pinlist { i0 i1 i2 0 } \
       CELL4

I am trying to get a subsection like this.

define_cell \
       -pinlist { i0 i1 i2 0 } \
       CELL3

When I am trying to do so with a simple script like below, I am actually getting from first match of define_cell till the end of the file contrary to my expectation.

awk '/define_cell/,/CELL3/{print $0}' <FILE>

How can I achieve the specific goal. I have tried to follow the solutions suggested in this. awk find the last match and print the next N lines But not able to get it to work.

Aucun commentaire:

Enregistrer un commentaire