Search & Replace also increment SOA

Search & Replace also increment SOA

am 23.03.2007 22:41:20 von Hawk

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@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Search & Replace also increment SOA

am 24.03.2007 00:51:30 von Williamawalters

--===============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@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:\@Work\Perl\hawk@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





Arial"=20
bottomMargin=3D7 leftMargin=3D7 topMargin=3D7 rightMargin=3D7> e_document=20
face=3DArial color=3D#000000 size=3D2>


hi hawk --  

 

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

 

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

 

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

 

C:\@Work\Perl\hawk@friend.ly.net>perl=20
-pe
"s/(?<=3Dly\.)com/net/g;
s/mail\.ly\.com/email\.ly\.net/g;
m=
y $sn=20
=3D qr/2005\d{6}/;  s/($sn)/ $1 + 1 /eg"  before  >=20
after

define $sn to be whatever matches unambiguously with your serial=20
number.  

be aware that  s/mail\.ly\.com/email\.ly\.net/g;  is a little=
=20
dangerous in that

something like ``email.ly.com'' will become ``eemail.ly.net''. &nb=
sp;=20
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  

 



font: normal 10pt ARIAL, SAN-SERIF;">
AOL now=20=
offers free email to everyone. Find out more about what's free from AOL at=20=
ww.aol.com?ncid=3DAOLAOF00020000000339" target=3D"_blank">AOL.com=
..


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

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

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1345993790==--