Anyway, I also have similar problems, which I use the following for (it's not quite the same as yours and I usually end up tweaking it). I just offer it as another solution. Sorry it's not completely in perl. :)
#!/bin/sh # query-replace files recursively, substituting in place STRING1=$1 STRING2=$2 find . -type f | xargs -n 255 perl -p000i.bak -e "s/${STRING1}/${STRIN +G2}/g"
And a little explanation:
`find` recursively descend the file system, and its argument "-type f" means get only look at text files (sometimes I insert "-name '*.html'". The output of `find` is a list of filenames, which are piped to `xargs`. I use `xargs` for efficiency, so that you're not starting and stopping the `perl` interpreter hundreds of times. "-n 255" shovels only 255 file names at a time, though, so that the maximum command-line arguments of the shell aren't exceeded. Finally, those files are passed as arguments (by `xargs`) to `perl`. The -p switch prints every line, but in this case each line is a "paragraph" because of the -0 switch using '00' special case end-line delimiter (I did that so you could match regexps over multiple lines). The -i switch edits "in place", with each file backed up to a file with '.bak' appended to the name.
Example usage:
$ query-replace.sh '\<(\/)?[hH]3\>' '\<${1}H1\>'
would take <H3> or </h3> and replace with <H1> and </H1>, respectively. It's a bit ugly, I admit. I end up using emacs usually.
In reply to Re: Search and Replace Entire Directories
by kwoff
in thread Search and Replace Entire Directories
by CiceroLove
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |