[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in grep when using both --after-context and --invert-match
From: |
Bob Proulx |
Subject: |
Re: Bug in grep when using both --after-context and --invert-match |
Date: |
Fri, 4 Nov 2005 11:26:09 -0700 |
User-agent: |
Mutt/1.5.9i |
Paul Jarc wrote:
> Oni Studio wrote:
> > Logically, i tried:
> > grep -v -A4 'zone "domain.com' /etc/bind/zones > /etc/bind/zones.new
> >
> > This did not produce the desired effect.
>
> Right. This gives you eery line that does not match your pattern,
> along with the following four lines. Here's one way to get what you
> want (untested):
> grep -A4 'zone "domain.com' /etc/bind/zones |
> diff - /etc/bind/zones |
> sed '/^> /!d;s/^> //'
Here is another way that I think I simpler using sed. Illustrated
using seq to generate test input.
seq 1 9 | sed '/4/,+3d'
1
2
3
8
9
So in your case something like this (untested):
sed '/zone "domain.com/,+3d' /etc/bind/zones
The sed -i,--in-place option can be very useful in this context too.
Bob