[Gllug] Search and replace in a whole folder

raphaël Benard raphy_02_4 at hotmail.com
Tue Dec 4 16:25:34 UTC 2007


Hello,

You want use the functionality	of Apache for make your task. But for severals other reasons you may need a script which do a s&r(search and replace). 

An example of script s&r with sed:

#!/bin/bash

val=`ls $1`

mkdir newfolder

for i in $val 
do
  sed  s/$2/$3/g  "$1/$i"> ./newfolder/$i
done




Name this script sr_script and make it excutable:

chmod 700 sr_script  

e.g for use it:

sr_script /path/yourfolder word_search  word_replace

Your folder with the change is the folder named "newfolder", then, you can backup the old folder and replace it by "newfolder".

If you want a script with most functionality  like manage the sub-folder, ask me.



> I need to update a few hundred HTML files. Basically, the footer of these
> webpages need updating. I could update them all manually, but I was
> wondering if there's a way of doing a search and replace on a whole folder?
> I understand that a command called gawk might help, but I don't know to use
> it. Any suggestions?
>
> Alex
_________________________________________________________________
Découvrez le blog Messenger Le Meilleur du Web : toutes les vidéos qui buzzent le plus sur Internet !
http://meilleurduweb.spaces.live.com/
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list