I would like do such a search and replace operation
that goes into subdirectories,
and replaces a block of text that spans many lines,
and replace it with a string.
I looked at rpl, but couldn't figure out how
to use it to replace a text block.
Can anyone help?
Thanks
I use a perl one-liner combined with find, like this:
perl -pi -e s#text1#text2# `find . -name "*.php"`
This goes into each *.php file in every subdirectory under the current
dir, and replaces text1 with text2. You can replace *.php with *.html
or * obviously. If you need slashes in the substitution (e.g. to alter
a pathname in multiple html files), you need to mask with a backslash,
such as s#var#var\/log#
Oh, and I think (no guarantee though, try it) it also creates some
kind of .bak files so you have backups, just in case.
s:
>
> perl -pi -e s#text1#text2# `find . -name "*.php"`
>
> This goes into each *.php file in every subdirectory under the current
> dir, and replaces text1 with text2. You can replace *.php with *.html
> or * obviously. If you need slashes in the substitution (e.g. to alter
> a pathname in multiple html files), you need to mask with a backslash,
> such as s#var#var\/log#
>
> Oh, and I think (no guarantee though, try it) it also creates some
> kind of .bak files so you have backups, just in case.
How do I use the provided script to replace a string
that spans many lines?
You might look at sed examples. Something like:
sed s/replace this/with this/ filename
sed "s/_samba/_samba\/\samba/" filename