From: osiris on
Is there a way to remove several lines from a file
(using e.g. sed or perl) where the lines have a pattern
beginning with a line-feed and pattern and
ending with a line-feed and blank-line?

It would be the the exact opposite
of the awk command:

awk '/^firstpattern/,/^$/' myfile

Many thanks.
From: Janis Papanagnou on
osiris(a)abydos.kmt wrote:
> Is there a way to remove several lines from a file
> (using e.g. sed or perl) where the lines have a pattern
> beginning with a line-feed and pattern and
> ending with a line-feed and blank-line?
>
> It would be the the exact opposite
> of the awk command:
>
> awk '/^firstpattern/,/^$/' myfile

"The exact opposite"?

awk '/^firstpattern/,/^$/ {next} 1' myfile


Janis

>
> Many thanks.
From: osiris on

On Sun, 12 Nov 2006 02:36:40 +0100, Janis Papanagnou <Janis_Papanagnou(a)hotmail.com> chiseled on limestone:
>
>osiris(a)abydos.kmt wrote:
>> Is there a way to remove several lines from a file
>> (using e.g. sed or perl) where the lines have a pattern
>> beginning with a line-feed and pattern and
>> ending with a line-feed and blank-line?
>>
>> It would be the the exact opposite
>> of the awk command:
>>
>> awk '/^firstpattern/,/^$/' myfile
>
>"The exact opposite"?

Thanks for your help and sorry for my lack of clarification.
By opposite, I meant everything else besides the pattern
found by awk above as in 'grep -v mypattern' being the opposite of
'grep mypattern'. Hope that's more clear.

> awk '/^firstpattern/,/^$/ {next} 1' myfile

This does do it correctly using nawk on my system
however, I realized that I can't really have a temporary file
so I have to use /bin/ed or perl. Can /bin/ed or perl do this?
From: Jon LaBadie on
osiris(a)abydos.kmt wrote:
> On Sun, 12 Nov 2006 02:36:40 +0100, Janis Papanagnou <Janis_Papanagnou(a)hotmail.com> chiseled on limestone:
>> osiris(a)abydos.kmt wrote:
>>> Is there a way to remove several lines from a file
>>> (using e.g. sed or perl) where the lines have a pattern
>>> beginning with a line-feed and pattern and
>>> ending with a line-feed and blank-line?
>>>
>>> It would be the the exact opposite
>>> of the awk command:
>>>
>>> awk '/^firstpattern/,/^$/' myfile
>> "The exact opposite"?
>
> Thanks for your help and sorry for my lack of clarification.
> By opposite, I meant everything else besides the pattern
> found by awk above as in 'grep -v mypattern' being the opposite of
> 'grep mypattern'. Hope that's more clear.
>
>> awk '/^firstpattern/,/^$/ {next} 1' myfile
>
> This does do it correctly using nawk on my system
> however, I realized that I can't really have a temporary file
> so I have to use /bin/ed or perl. Can /bin/ed or perl do this?

echo '/^firstpattern/,/^$/d
w
q' | /bin/ed - myfile
From: John W. Krahn on
osiris(a)abydos.kmt wrote:
> Is there a way to remove several lines from a file
> (using e.g. sed or perl) where the lines have a pattern
> beginning with a line-feed and pattern and
> ending with a line-feed and blank-line?
>
> It would be the the exact opposite
> of the awk command:
>
> awk '/^firstpattern/,/^$/' myfile

perl -ne'/^firstpattern/ .. /^$/ or print' myfile


John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall