Re: multi-line matches / named.conf parsing

2003-06-24 Thread Jeff 'japhy' Pinyan
On Jun 24, Kevin Pfeiffer said:

>>> sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile
>>>
>>> How might one do this in Perl?
>>
>> perl -ne 'print unless /zone "domain.com" {/ .. /};/' \
>> /etc/named.conf > newfile
>
>Cool, I didn't think of Perl's range operator "..".

Don't be fooled.  Just because it looks like a duck doesn't mean it's a
duck.  In this case, the .. operator is the flip-flop operator.  In scalar
context, .. is flip-flop, while in list context, .. is range.

perldoc perlop

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: multi-line matches / named.conf parsing

2003-06-24 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Paul 
Johnson wrote:

> 
> Kevin Pfeiffer said:
> 
>> In comp.unix.shell Alan Murrell posted this clever sed solution for
>> removing entries from his named.conf file using only the domain name):
>>
>> sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile
>>
>> Instead of using actual line numbers for the range of lines (such as
>> "1,4") he uses two regexes that match to them.
>>
>> How might one do this in Perl?
> 
> Just the same way:
> 
> perl -ne 'print unless /zone "domain.com" {/ .. /};/' \
> /etc/named.conf > newfile

Cool, I didn't think of Perl's range operator "..".
 

-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: multi-line matches / named.conf parsing

2003-06-24 Thread Dan Muey
> > sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile
> >
> > Instead of using actual line numbers for the range of lines (such as
> > "1,4") he uses two regexes that match to them.
> >
> > How might one do this in Perl?
> 
> Just the same way:
> 
> perl -ne 'print unless /zone "domain.com" {/ .. /};/' \
> /etc/named.conf > newfile

Way better than my clunky idea!

Dan

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: multi-line matches / named.conf parsing

2003-06-24 Thread Dan Muey
> Hi all,

Howdy,

> 
> In comp.unix.shell Alan Murrell posted this clever sed 
> solution for removing 
> entries from his named.conf file using only the domain name):
> 
> sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile
> 
> Instead of using actual line numbers for the range of lines 
> (such as "1,4") 
> he uses two regexes that match to them.
> 
> How might one do this in Perl? Read in the whole file and then do a 
> multi-line substitution? 
> 
> Or a 'bigger' solution would be to read the lines one at a 
> time into a hash 
> structure ($domain{domain.com} for ex.), starting a new hash 
> key each time 
> one matches /^\s*zone.*/ ? This would then let one sort, do 
> whatever, and 
> write out the entire file afterwards in proper format.
> 
> No solution needed, just wondering about approaches (small and large).

Well, assuming your conf file isn't too huge, IE the size you could use File::Slurp on.

use File::Slurp;
my %named_conf = parse_conf(read_file("/etc/namedb/named.conf"));

Now parse_conf() takes the array that read_file() returned, and similar to what you 
said:

At a 'zone' file get domain then until it gets the };
It adds each attribute as a key and it's value as a value.

So you end up with a hash like this:

$named_conf{'domain.com'} => type => 'master',
 file => '/etc/named/master/domain.zone';
$named_conf{'domain2.net'} => type => 'slave',
file => '...',
masters => '1.1.1.1;2.2.2.2;
 
Or something like that, the syntax may be bad since I'm busy but that's the idea.

Although you said you simply want to remove a zone entry som that may be overkill now 
that I remmebere that.

How about :

 perl -e "use File::Slurp; $n = read_file('/etc/named.conf');$n =~ s/zone 
\"removeme.com\".*\}\;//" 

HTH

Dmuey

> -K
> 
> __DATA__
> zone "domain.com" {
> type master;
> file "domain.com";
> };
> zone "domain2.com" {
> type master;
> file "domain2.com";
> };
> ##

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: multi-line matches / named.conf parsing

2003-06-24 Thread Paul Johnson

Kevin Pfeiffer said:

> In comp.unix.shell Alan Murrell posted this clever sed solution for
> removing entries from his named.conf file using only the domain name):
>
> sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile
>
> Instead of using actual line numbers for the range of lines (such as
> "1,4") he uses two regexes that match to them.
>
> How might one do this in Perl?

Just the same way:

perl -ne 'print unless /zone "domain.com" {/ .. /};/' \
/etc/named.conf > newfile

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



multi-line matches / named.conf parsing

2003-06-24 Thread Kevin Pfeiffer
Hi all,

In comp.unix.shell Alan Murrell posted this clever sed solution for removing 
entries from his named.conf file using only the domain name):

sed '/zone "domain.com" {/,/};/d' /etc/named.conf > newfile

Instead of using actual line numbers for the range of lines (such as "1,4") 
he uses two regexes that match to them.

How might one do this in Perl? Read in the whole file and then do a 
multi-line substitution? 

Or a 'bigger' solution would be to read the lines one at a time into a hash 
structure ($domain{domain.com} for ex.), starting a new hash key each time 
one matches /^\s*zone.*/ ? This would then let one sort, do whatever, and 
write out the entire file afterwards in proper format.

No solution needed, just wondering about approaches (small and large).

-K

__DATA__
zone "domain.com" {
type master;
file "domain.com";
};
zone "domain2.com" {
type master;
file "domain2.com";
};
##


-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]