Re: search and replace code in php or html files
Casey T. Deccio wrote:
>
> find . -name "*.html" | xargs sed -i.bak -e
> 's/string_to_replace/replacement/g'
>
> Does something like this work? If your match pattern spans more than
> one line than you'll need a more complex script.
>
> Casey
>
>
>
For all cases so far, I haven't had any need to replace multiple lines.
So this was easier. I used:
$> perl -p -i.bak -e "s/ToBeReplaced/ReplacedWith/g;" index.php
and I could use a file pattern instead of only single file (index.php
above) or explicitly name the files I want changed. And I guess multiple
'-e s/pattern1/pattern2/g' would do multiple subsitutions at once. So
for simple string replacements, this is workng fine. I am yet to
encounter a case with multiple lines.
Thanks,
->HS
Reply to: