Print Lines between two regexes

Hi I have a file like this

I need to delete all the lines between SQ and // and not the lines containing them.

So the desired output should be

I tried by using flip-flop operator

perl -wlne 'print if !(/SQ/../\/\//)'

But its not printing the lines containing regexes.

Thanks in advance:b:

Hi polsum,

Try (using flip-flop in perl):

$ perl -wlne 'if ( $c = (m|SQ|..m|//|) ) { next unless $c == 1 || $c =~ m/E0$/ } print' infile
SQ kkk m99029 wwwAV
//
AS
DS
SQ ooo l9909 qqqqa
//

Regards,
Birei

1 Like

another way using awk:

awk '/SQ/ { P=1; print }; /\/\// { P=0; print }; !P' filename
1 Like

Thank you very much guys. Both are working great.

I think the second print is an extra one see o/p below , you need to remove it.

o/p

SQ kkk m99029 wwwAV
//
//
AS
DS
SQ ooo l9909 qqqqa
//
//
nawk '/SQ/ { P=1;print}; /\/\// { P=0}; !P' filename

o/p:

SQ kkk m99029 wwwAV
//
AS
DS
SQ ooo l9909 qqqqa
//