I can never remember how to do this, I always have to try the 10 versions of perldoc help then resort to google searches… So, documentation in a common place seems like a nice idea.

Start with a directory of files, or a list of them you can get in some reasonable fashion:

for d in `ls postfix-198*/config/main.cf`; do
 perl-magic-goo-here
done

Now, what is ‘perl-magic-goo-here’ you ask? Me too, starting with this link from google on perl.com has some handy-dandy info near the bottom of the page in the ‘in place editting’ section:

perl -i.bak -pe 's/\bPHP\b/Perl/g' file.txt

Which does:

  1. -i.bak == save originals as original.bak
  2. -pe == loop over each line of file.txt applying the command: “s/PHP/Perl/” (swap PHP for Perl)

Excellent, exactly what we want! Now:

for d in `ls postfix-198*/config/main.cf` ; do
  perl -i.2007-03-24 -pe 's/^mynetworks = 209.133.111.64\/27/mynetworks = 216.206.180.0\/24, 209.133.111.64\/27/' ${d}
done

That ought to fix the files inplace and leave behind files named after the date of change even!