From catenate at yahoo.com Thu Nov 4 15:53:11 1999 From: catenate at yahoo.com (Nate) Date: Thu Aug 5 00:03:10 2004 Subject: substitution problems using perl Message-ID: <19991104215311.4512.rocketmail@web901.mail.yahoo.com> On the Jax.PM jacksonville-pm-list; Nate wrote - Hello again JaxPM! I moved to Silicon Valley and got a job as a sys admin and Perl scripter at a web hosting company. I'm really busy rebooting the 10 or so NT webservers all the time ;) and just monitoring the Linux box that has been up and running for 234 days straight :) Anyways, I'm converting some zone files using perl (to move to new IP's in a new location), and I've already made changes in the min TTL in the files, and now I'm changing the serial numbers on each file, but I can't get it to line up like it did before. I'd like to stick two tabs at the beginning of the replacement text. here's what it looks like before the change: @ IN SOA ns.comcity.com. webmaster.comcity.com. ( 99102901 43200 7200 604800 3600 ) then I run at the (windoze port of) bash command line: c:\>perl -pi.bak -e 's/^\t\t9\d*$/99110420/e' COMCITY.zone and I get this: @ IN SOA ns.comcity.com. webmaster.comcity.com. ( 99110420 43200 7200 604800 3600 ) Notice how I need the two tabs at the beggining? I tried this: c:\>perl -pi.bak -e 's/^\t\t9\d*$/\t\t99110420/e' COMCITY.zone and this c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"\t\t99110420"/e' COMCITY.zone What's the right way? I'm sure it's easy, but I don't see the answer. Please reply to me directly, I haven't subscribed this account to JaxPM. P.S. Here's an interesting one: what if I wanted to save the matched number, and increment it by one? Something like: c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"$1++"/e' COMCITY.zone ===== nate catenate@yahoo.com my infosec favorites -> www.geocities.com/catenate/ There is no time BUT now. __________________________________________________ Do You Yahoo!? Bid and sell for free at http://auctions.yahoo.com The Jacksonville Perl Monger's Group is operated by - Bill -Sneex- Jones ( sneex@usa.net ), to whom send all praises, complaints, or comments... From sml at zfx.com Thu Nov 4 16:27:30 1999 From: sml at zfx.com (Steve Lane) Date: Thu Aug 5 00:03:10 2004 Subject: substitution problems using perl References: <19991104215311.4512.rocketmail@web901.mail.yahoo.com> Message-ID: <38220852.6231@zfx.com> On the Jax.PM jacksonville-pm-list; Steve Lane wrote - Nate wrote: > Notice how I need the two tabs at the beggining? > > I tried this: > c:\>perl -pi.bak -e 's/^\t\t9\d*$/\t\t99110420/e' COMCITY.zone > > and this > > c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"\t\t99110420"/e' COMCITY.zone > > What's the right way? I'm sure it's easy, but I don't see the answer. think of what the /e is doing. it treats the right side as a Perl expression, evaluates it, and uses the return value as the substitution. the simplest would be just "s/^(\t\t9\d*)$/\t\t99110420/". notice no /e; it's not necessary. you only need /e if you have a substitution that can't be expressed as a double-quoted string, and your substitution can. > P.S. Here's an interesting one: what if I wanted to save the matched > number, and increment it by one? > Something like: > c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"$1++"/e' COMCITY.zone you'll want to get rid of the double-quotes, as you'll get "99110420++" as a substitution with them. without the quotes it should work. i haven't tested any of this... so hopefully i'm not wrong. i'm sure someone will correct me if i am. -- Steve Lane The Jacksonville Perl Monger's Group is operated by - Bill -Sneex- Jones ( sneex@usa.net ), to whom send all praises, complaints, or comments... From jproctor at oit.umass.edu Fri Nov 5 08:25:56 1999 From: jproctor at oit.umass.edu (j proctor) Date: Thu Aug 5 00:03:10 2004 Subject: substitution problems using perl In-Reply-To: <19991104215311.4512.rocketmail@web901.mail.yahoo.com> Message-ID: On the Jax.PM jacksonville-pm-list; j proctor wrote - > I moved to Silicon Valley and got a job as a sys admin and Perl > scripter at a web hosting company. Cool. Congrats. > P.S. Here's an interesting one: what if I wanted to save the matched > number, and increment it by one? > Something like: > c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"$1++"/e' COMCITY.zone s/^\t\t(9\d*)$/$1++/e should be closer (note the ()'s don't enclose the \t's). I, like what's-his-name that also responded, am too lazy to go test this myself. You actually have a slightly more complicated question; if I were writing such a tool, I'd probably not try to run it in place from the command line, and add some logic to update the date-stamp part of the serial number, too. And while I was at it, I'd make a point to switch to a 1999110521 format (for example), because it's still obvious what's going on, and it won't break when you want to update something 2 months from now (IIRC serial numbers have to increase with each update). j The Jacksonville Perl Monger's Group is operated by - Bill -Sneex- Jones ( sneex@usa.net ), to whom send all praises, complaints, or comments... From catenate at yahoo.com Mon Nov 8 17:23:41 1999 From: catenate at yahoo.com (Nate) Date: Thu Aug 5 00:03:10 2004 Subject: substitution problems using perl Message-ID: <19991108232341.7514.rocketmail@web903.mail.yahoo.com> On the Jax.PM jacksonville-pm-list; Nate wrote - --- j proctor wrote: > On the Jax.PM jacksonville-pm-list; > j proctor wrote - > > > P.S. Here's an interesting one: what if I wanted to save the > matched > > number, and increment it by one? > > Something like: > > c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"$1++"/e' COMCITY.zone > You actually have a slightly more complicated > question; > if I were writing such a tool, I'd probably not try to run it in > place > from the command line, and add some logic to update the date-stamp > part of > the serial number, too. I actually was doing this from the command line so that I could do this: c:\>perl -pi.bak -e 's/^\t\t(9\d*)$/$1++/' *.zone and use the shell's wildcard features, trying to keep this just a quick script. Of course, once I had to debug it it was no longer a quick command line script! Thanks again, guys. ===== nate catenate@yahoo.com my infosec favorites -> www.geocities.com/catenate/ There is no time BUT now. __________________________________________________ Do You Yahoo!? Bid and sell for free at http://auctions.yahoo.com The Jacksonville Perl Monger's Group is operated by - Bill -Sneex- Jones ( sneex@usa.net ), to whom send all praises, complaints, or comments... From catenate at yahoo.com Mon Nov 8 17:23:41 1999 From: catenate at yahoo.com (Nate) Date: Thu Aug 5 00:03:10 2004 Subject: substitution problems using perl Message-ID: <19991108232341.7514.rocketmail@web903.mail.yahoo.com> On the Jax.PM jacksonville-pm-list; Nate wrote - --- j proctor wrote: > On the Jax.PM jacksonville-pm-list; > j proctor wrote - > > > P.S. Here's an interesting one: what if I wanted to save the > matched > > number, and increment it by one? > > Something like: > > c:\>perl -pi.bak -e 's/^(\t\t9\d*)$/"$1++"/e' COMCITY.zone > You actually have a slightly more complicated > question; > if I were writing such a tool, I'd probably not try to run it in > place > from the command line, and add some logic to update the date-stamp > part of > the serial number, too. I actually was doing this from the command line so that I could do this: c:\>perl -pi.bak -e 's/^\t\t(9\d*)$/$1++/' *.zone and use the shell's wildcard features, trying to keep this just a quick script. Of course, once I had to debug it it was no longer a quick command line script! Thanks again, guys. ===== nate catenate@yahoo.com my infosec favorites -> www.geocities.com/catenate/ There is no time BUT now. __________________________________________________ Do You Yahoo!? Bid and sell for free at http://auctions.yahoo.com The Jacksonville Perl Monger's Group is operated by - Bill -Sneex- Jones ( sneex@usa.net ), to whom send all praises, complaints, or comments...