[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Multible search and replace?



> Was just wondering if there is a package out that does multiple file
> search and replaces?  I have to go through my main html directory and make
> a lot of repetive changes.  Was wondering if there was a package or a perl
> script laying arround to do this.  Would same me the time of writing one
> up.

Well, this is so easy to do in perl that I just write little programs to
do it on the fly most of the time. Here's a little program that may do
what you want:

#!/usr/bin/perl -i.bak
$find=shift; $replace=shift;
while (<>) { s/$find/$replace/g; print }

Name it replace and call it like so:
replace from to file [file ...]

It can operate on multiple files, 'from' is the string you want to find,
and it is replaced globally with 'to' in all the files. Backups are saved
with a .bak extention. 

-- 
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj #  RSA-3-lines-perl
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1 #         Joey Hess
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)   #  joey@kite.ml.org
                      "He. He. He." - - Herman Toothrot



--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-REQUEST@lists.debian.org . Trouble? e-mail to Bruce@Pixar.com


Reply to: