Search & Replace also increment SOA

Hi,

Wondering if someone help with writing a perl script to do this:

Before:
;BIND DUMP V8
$ORIGIN com.
metropolitanbathtile 86400 IN NS ns1.ly.com. ;Cl=2
86400 IN NS ns2.ly.com. ;Cl=2
86400 IN SOA ns1.ly.com. webmaster.friend.ly.net. (
2005011101 10800 3600 604800 86400 ) ;Cl=2
86400 IN A 12.167.149.135 ;Cl=2
$ORIGIN metropolitanbathtile.com.
* 86400 IN A 12.167.149.135 ;Cl=2

After:

;BIND DUMP V8
$ORIGIN com.
metropolitanbathtile 86400 IN NS ns1.ly.net. ;Cl=2
86400 IN NS ns2.ly.net. ;Cl=2
86400 IN SOA ns1.ly.net. webmaster.friend.ly.net. (
2005011102 10800 3600 604800 86400 ) ;Cl=2
86400 IN A 12.167.149.135 ;Cl=2
$ORIGIN metropolitanbathtile.com.
* 86400 IN A 12.167.149.135 ;Cl=2


--- replace ly.com to ly.net
--- if mail.ly.com exist, then replace with email.ly.net
--- increment serial: 2005011101 to 2005011102


I know I can do this easily with sed but don't know how to increment the
serial number.

Thx in advance


_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Hawk [ Fr, 23 März 2007 22:41 ] [ ID #1667163 ]

Re: Search & Replace also increment SOA

--===============1345993790==
Content-Type: multipart/alternative;
boundary="-----------------------------1174693890"


-------------------------------1174693890
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit


hi hawk --

In a message dated 3/23/2007 4:42:38 P.M. Eastern Standard Time,
Hawk [at] Friend.ly.Net writes:

> Hi,
>
> Wondering if someone help with writing a perl script to do this:
>
> Before:
> ;BIND DUMP V8
> $ORIGIN com.
> metropolitanbathtile 86400 IN NS ns1.ly.com. ;Cl=2
> 86400 IN NS ns2.ly.com. ;Cl=2
> 86400 IN SOA ns1.ly.com. webmaster.friend.ly.net. (
> 2005011101 10800 3600 604800 86400 ) ;Cl=2
> 86400 IN A 12.167.149.135 ;Cl=2
> $ORIGIN metropolitanbathtile.com.
> * 86400 IN A 12.167.149.135 ;Cl=2
>
> After:
>
> ;BIND DUMP V8
> $ORIGIN com.
> metropolitanbathtile 86400 IN NS ns1.ly.net. ;Cl=2
> 86400 IN NS ns2.ly.net. ;Cl=2
> 86400 IN SOA ns1.ly.net. webmaster.friend.ly.net. (
> 2005011102 10800 3600 604800 86400 ) ;Cl=2
> 86400 IN A 12.167.149.135 ;Cl=2
> $ORIGIN metropolitanbathtile.com.
> * 86400 IN A 12.167.149.135 ;Cl=2
>
>
> --- replace ly.com to ly.net
> --- if mail.ly.com exist, then replace with email.ly.net
> --- increment serial: 2005011101 to 2005011102
>
>
> I know I can do this easily with sed but don't know how to increment the
> serial number.
>
> Thx in advance


try something like this (assuming input is in file named ``before''):

C:\ [at] Work\Perl\hawk [at] friend.ly.net>perl -pe
"s/(?<=ly\.)com/net/g;
s/mail\.ly\.com/email\.ly\.net/g;
my $sn = qr/2005\d{6}/; s/($sn)/ $1 + 1 /eg" before > after

define $sn to be whatever matches unambiguously with your serial number.
be aware that s/mail\.ly\.com/email\.ly\.net/g; is a little dangerous in
that
something like ``email.ly.com'' will become ``eemail.ly.net''. maybe put a
\b word boundary assertion in front of the pattern,
i.e., s/ \b mail\.ly\.com / email\.ly\.net /xg;

hth -- bill walters





************************************** AOL now offers free email to everyone.
Find out more about what's free from AOL at http://www.aol.com.

-------------------------------1174693890
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3DUS-ASCII">
<META content=3D"MSHTML 6.00.2800.1479" name=3DGENERATOR></HEAD>
<BODY id=3Drole_body style=3D"FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: =
Arial"
bottomMargin=3D7 leftMargin=3D7 topMargin=3D7 rightMargin=3D7><FONT id=3Drol=
e_document
face=3DArial color=3D#000000 size=3D2>
<DIV>
<DIV>hi hawk --   </DIV>
<DIV> </DIV>
<DIV>In a message dated 3/23/2007 4:42:38 P.M. Eastern Standard Time,
Hawk [at] Friend.ly.Net writes:</DIV>
<DIV> </DIV>
<DIV>> Hi,<BR>> <BR>> Wondering if someone help with writing a perl=

script to do this:<BR>> <BR>> Before:<BR>> ;BIND DUMP V8<BR>>
$ORIGIN com.<BR>> metropolitanbathtile    86400  =
;
IN      NS     
ns1.ly.com.    
;Cl=3D2<BR>>         86400 &=
nbsp;
IN      NS     
ns2.ly.com.    
;Cl=3D2<BR>>         86400 &=
nbsp;
IN      SOA     ns1.ly.com.
webmaster.friend.ly.net.
(<BR>>           &=
nbsp;    
2005011101 10800 3600 604800 86400 )   
;Cl=3D2<BR>>         86400 &=
nbsp;
IN      A      
12.167.149.135  ;Cl=3D2<BR>> $ORIGIN metropolitanbathtile.com.<BR>&g=
t;
*       86400  
IN      A      
12.167.149.135  ;Cl=3D2<BR>> <BR>> After:<BR>> <BR>> ;BIND =
DUMP
V8<BR>> $ORIGIN com.<BR>> metropolitanbathtile   
86400   IN     
NS      ns1.ly.net.    
;Cl=3D2<BR>>         86400 &=
nbsp;
IN      NS     
ns2.ly.net.    
;Cl=3D2<BR>>         86400 &=
nbsp;
IN      SOA     ns1.ly.net.
webmaster.friend.ly.net.
(<BR>>           &=
nbsp;    
2005011102 10800 3600 604800 86400 )   
;Cl=3D2<BR>>         86400 &=
nbsp;
IN      A      
12.167.149.135  ;Cl=3D2<BR>> $ORIGIN metropolitanbathtile.com.<BR>&g=
t;
*       86400  
IN      A      
12.167.149.135  ;Cl=3D2<BR>> <BR>> <BR>> --- replace ly.com to=

ly.net<BR>> --- if mail.ly.com exist, then replace with email.ly.net<BR>&=
gt;
--- increment serial: 2005011101 to 2005011102<BR>> <BR>> <BR>> I k=
now
I can do this easily with sed but don't know how to increment the<BR>> se=
rial
number.<BR>> <BR>> Thx in advance<BR></DIV>
<DIV> </DIV>
<DIV>try something like this (assuming input is in file named
``before''):   </DIV>
<DIV> </DIV>
<DIV>C:\ [at] Work\Perl\hawk [at] friend.ly.net>perl
-pe<BR>"s/(?<=3Dly\.)com/net/g;<BR>s/mail\.ly\.com/email\.ly\.net/g;<BR>m=
y $sn
=3D qr/2005\d{6}/;  s/($sn)/ $1 + 1 /eg"  before  >
after<BR></DIV>
<DIV>define $sn to be whatever matches unambiguously with your serial
number.   </DIV>
<DIV>be aware that  s/mail\.ly\.com/email\.ly\.net/g;  is a little=

dangerous in that </DIV>
<DIV>something like ``email.ly.com'' will become ``eemail.ly.net''. &nb=
sp;
maybe put a </DIV>
<DIV>\b word boundary assertion in front of the pattern, </DIV>
<DIV>i.e.,  s/ \b mail\.ly\.com / email\.ly\.net /xg;</DIV>
<DIV> </DIV>
<DIV>hth -- bill walters   </DIV>
<DIV> </DIV></DIV></FONT><BR><BR><BR><DIV><FONT style=3D"color: black; =
font: normal 10pt ARIAL, SAN-SERIF;"><HR style=3D"MARGIN-TOP: 10px">AOL now =
offers free email to everyone. Find out more about what's free from AOL at =
<A title=3D"http://www.aol.com?ncid=3DAOLAOF00020000000339" href=3D"http://w=
ww.aol.com?ncid=3DAOLAOF00020000000339" target=3D"_blank"><B>AOL.com</B></A>=
.. </FONT></DIV></BODY></HTML>

-------------------------------1174693890--

--===============1345993790==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1345993790==--
Williamawalters [ Sa, 24 März 2007 00:51 ] [ ID #1667164 ]
Perl » gmane.comp.lang.perl.active-perl » Search & Replace also increment SOA

Vorheriges Thema: Patrick J FINNEGAN is out of the office.
Nächstes Thema: RTF Tables