|
|
| Author |
Message |
gotissues68
RealPoor Sensei

Joined: 21 Aug 2003 Posts: 1866
|
Posted: 11/12/04 - 02:09 Post subject: sin or dunn regex question
|
|
|
I'm trying to figure this out on my own but I'd rather be flamed by the realpoor people's then by someone in a perl newsgroup.. dunno if there's a regex newsgroup.
Anyways here's what I'm trying to work out..
I have the following multi-line
zone blah.net {
type master;
database mysql named blah.net 127.0.0.1;
};
what I would like to accomplish is to convert anything on the 3rd line of the expression to blah_net 127.0.0.1, so I'm essentially looking to convert a period to an underscore but only on non-numeric characters.
I use the following...
sed -e 3s/\\.\\\([^0-9]\\\)/_\\\1/g named.dbtest
drew@socrates:~$ sed -e 3s/\\.\\\([^0-9]\\\)/_\\\1/g named.dbtest
zone techiekb.com {
type master;
database mysql named techiekb_com 127.0.0.1;
};
zone fuckingbitter.com {
type master;
database mysql named fuckingbitter.com 127.0.0.1;
};
As you can see I managed to match the 3rd line of the expression but I want to match the 3rd line of each of the 4 line expression =\ I just found the line matching info while I was posting this.. so its gotten me a bit further.. I'm reading through my regex book as well to see if I can find my own answer Any ideas to point me in the right direction would be most greatly appreciated.
|
|
|
Back to top
|
|
|
|
 |
sinrakin
RealPoor Master of Posts

Joined: 11 Oct 2002 Posts: 7044
|
Posted: 11/12/04 - 05:46 Post subject:
|
|
|
There's always an elegant way to do stuff in Perl, but Perl is so huge these days that I can never remember how to do without yanking out the book, so I tend to stick to sed and awk. If it's something where you have to keep track of where you are on multiple lines (like every 4 lines or whatever) awk is a lot easier, since you can just write it like 'C' and throw in counters and stuff to keep track of where you are.
If you can take advantage of patterns on the same line though sed is fine. So for example if the line you want to change always starts with "database", you can do it like this:
sed -e '/^database/s/\.\([^0-9]\)/_\1/g' named.dbtest
My shell uses slightly different escapes than yours, but it's exactly what you had, except it uses a pattern /^database/ in front of the 's' command to say only apply the 's' command to lines that start with "database" in the first column:
~% sed -e '/^database/s/\.\([^0-9]\)/_\1/g' named.dbtest
zone techiekb.com {
type master;
database mysql named techiekb_com 127.0.0.1;
};
zone fuckingbitter.com {
type master;
database mysql named fuckingbitter_com 127.0.0.1;
};
|
|
|
Back to top
|
|
|
|
 |
gotissues68
RealPoor Sensei

Joined: 21 Aug 2003 Posts: 1866
|
Posted: 11/12/04 - 09:12 Post subject:
|
|
|
<3 Sin thank you so much! regex's are not my strong point and I just needed to get my head wrapped around that one, it'll make managing 100+ domains alot easier this morning now!
|
|
|
Back to top
|
|
|
|
 |
khrath
RealPoor Master of Posts

Joined: 11 Oct 2002 Posts: 8750
|
Posted: 11/12/04 - 09:18 Post subject:
|
|
|
nameservers are such a piece of shit pain in the ass.
when are they supposed to change to 5 minute propogation time?
I read about that like a few months ago.
|
|
|
Back to top
|
|
|
|
 |
sinrakin
RealPoor Master of Posts

Joined: 11 Oct 2002 Posts: 7044
|
Posted: 11/12/04 - 11:23 Post subject:
|
|
|
I know. I had a domain that wasn't propagated for three days two weeks ago and I was thinking the same thing.
BTW, another way to do it, if you're on linux, or using a sed derived from Gnu (which you probably are), and the file is nicely formatted, would be:
sed -e '3~5s/\.\([^0-9]\)/_\1/g' named.dbtest
The "3~5" means apply the pattern to every fifth line, starting with line 3. That depends on having no extra or missing blank lines between entries though, so it's a little fragile.
|
|
|
Back to top
|
|
|
|
 |
khrath
RealPoor Master of Posts

Joined: 11 Oct 2002 Posts: 8750
|
|
|
Back to top
|
|
|
|
 |
gotissues68
RealPoor Sensei

Joined: 21 Aug 2003 Posts: 1866
|
Posted: 11/12/04 - 12:50 Post subject:
|
|
|
|
Yea thats coming off a Slackware box Sin... And I remember someoen from Verisign posting to one of the network operator lists or bugtraq if I remember correctly a couple months ago about proper propogation. In case you guys are interested the whole reason I'm formatting that is because I'm using a patched version of Bind that allow access via a mysql database that stores your data for the zone, whats cool about it is that you don't have to restart the name server everytime you update something, as long as its not a new zone the changes take immediate effect since they are coming out of the db... and I wrote a web front end for it so people can manage their own shit on my box as I'm lazy... heh
|
|
|
Back to top
|
|
|
|
 |
Frashii
Sir Postalot

Joined: 11 Oct 2002 Posts: 1338
Location: Anchorage, AK
|
Posted: 11/12/04 - 13:26 Post subject:
|
|
|
Since you didn't ask me..
I shant hepl you with neato regexp hepl.
<3
Frashii
Ps. Looking into it!
|
|
|
Back to top
|
|
|
|
 |
Frashii
Sir Postalot

Joined: 11 Oct 2002 Posts: 1338
Location: Anchorage, AK
|
Posted: 11/12/04 - 13:28 Post subject:
|
|
|
nm. you got it figured out.
To use the regexp with the braces delimiting sections, you might look into pattern buffers.
|
|
|
Back to top
|
|
|
|
 |
khrath
RealPoor Master of Posts

Joined: 11 Oct 2002 Posts: 8750
|
Posted: 11/12/04 - 13:28 Post subject:
|
|
|
| Frashii wrote: | Since you didn't ask me..
I shant hepl you with neato regexp hepl.
<3
Frashii
Ps. Looking into it! |
I bet you own a pink shirt don't you?
play eq2 and be another bard, like nobody plays them.
|
|
|
Back to top
|
|
|
|
 |
gotissues68
RealPoor Sensei

Joined: 21 Aug 2003 Posts: 1866
|
Posted: 11/12/04 - 13:29 Post subject:
|
|
|
| Frashii wrote: | Since you didn't ask me..
I shant hepl you with neato regexp hepl.
<3
Frashii
Ps. Looking into it! |
aww Freshii ... I didn't mean to ignore you! I just knew Dunn and Sin were uber regex g33ks.. plus I don't know how often you browse the board! <3 you Mr Frashii
|
|
|
Back to top
|
|
|
|
 |
Occulis
RealPoor Jedi

Joined: 11 Oct 2002 Posts: 13293
Location: Moral Relativity Central
|
Posted: 11/12/04 - 16:24 Post subject:
|
|
|
|
FRASHII IS NEVER here and I am weeping inside
|
|
|
Back to top
|
|
|
|
 |
ATM Banana
RealPoor Master of Posts

Joined: 02 Jan 2003 Posts: 8575
|
Posted: 11/12/04 - 17:09 Post subject:
|
|
|
|
occ needs a big man to hold him.
|
|
|
Back to top
|
|
|
|
 |
Occulis
RealPoor Jedi

Joined: 11 Oct 2002 Posts: 13293
Location: Moral Relativity Central
|
Posted: 11/12/04 - 17:16 Post subject:
|
|
|
This calls for Big Men. For Big Times.
|
|
|
Back to top
|
|
|
|
 |
|
|