Re: block-based editing



Le Wed, 24 May 2006 03:55:56 -0700, aryzhov a écrit :

Hello All,

This must be a simple question, but since I am an "inline AWK
programmer",
figuring it out may take hours if not days for me.
Or I could split and join using an ugly shell script.
That's a last resort, but maybe there's a better idea?

I've got this input::

*****
whatever
... good pattern ...
whatever
*****
whatever
whatever
... good pattern ...
whatever
*****
... bad pattern ...
whatever
*****
whatever
..good pattern
whatever
*******

i.e. multiple blocks of text separated with ****, with eilter good
of bad pattern in them (one per block only). I want to get rid
of entire blocks with bad pattern, along with either preceeding
or following delimiter ****

If you can have the choice for your separators I'd advise you to
change the very special '*' to something more casual :-)

If so, saying your separator is '+++++' (five plus), this would do :

$ gawk '/good pattern/' RS=+++++

If you're stuck with the star, or non gawk, let's hope it'll be
indifferent to how many there are on the separator line, if so, use :

$ awk '/good pattern/' RS=*

If these don't work, please show sample results on your system (and
describe the sys/awk you have), we'll may have to use circular buffers
or else ;-)

.