[Gllug] Search and replace in a whole folder
Matthew King
matthew.king at monnsta.net
Tue Dec 4 16:57:09 UTC 2007
raphaël Benard <raphy_02_4 at hotmail.com> writes:
> 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
for i in val; do sed s/$2/$3/g "$1/$i" > ./newfolder/$i; done
I'd also add "s around everything with a variable so that it supports
spaces and most other vaguely evil characters, but you don't even need a
script:
$ sed 's/old/new/g' -i.bak /path/to/files/*
But I'd rather go with Jason's suggestion of a separately included file.
Matthew
--
I must take issue with the term "a mere child", for it has been my
invariable experience that the company of a mere child is infinitely
preferable to that of a mere adult.
-- Fran Lebowitz
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list