[lug] Publishing config files

Daniel Webb lists at danielwebb.us
Fri Nov 11 18:19:12 MST 2005


On Fri, Nov 11, 2005 at 05:54:07PM -0700, David L. Anselmi wrote:

> Daniel Webb wrote:
> [...]
> >For the Asterisk config example, I want to do something like this:
> >
> >; !!!REPLACE:12341234:XXXXXXXX!!!
> >exten = 12341234,1,SetCIDNum(1112223333)
> >exten = 12341234,2,SetCIDName(Someone)
> >exten = 12341234,3,Goto(calling_card,s,1)
> 
> Rather than a comment that says "12341234 needs replacing", how about a 
> comment that says "this is the Perl to run to sanitize this file".  Then 
> you write a script that processes the the files and runs the appropriate 
> code for each.
> 
> Maybe that's overkill for your case--you always have one (or a few) 
> strings in a file to replace.  But in the case of a shadow file, etc., 
> you might have a field that needs replaced.

I'm thinking of several different filetypes (Asterisk, Mutt, Vim, etc), and
each will have different things that will need sanitizing.  I'm sure it will
all be by hand, there's no way to predict from a pattern which things will be
"sensitive" and which won't.  I want the instruction to replace right next to
the line where the replace will happen, because I know if I don't, I'll end up
changing the line sometime in the future, the pattern won't match any more,
and stuff I don't want on the net will be there.  It's guaranteed to happen,
so I'm not going to risk it.  If the REPLACE line is right there, I'll
remember to change it any time I change the line.

> But how's this (works at least for the above, leave off the trailing !!!):
> 
> #!/usr/bin/perl -lp
> 
> if /!!!REPLACE/ {
>   (undef, $pat, $repl) = split(/:/);
>   $_ = "";
> }
> s/$pat/$repl/;

Excellent!  That's should do it.  I know it's obvious, but I haven't used Perl
for a couple of years.




More information about the LUG mailing list