[Cialug] find and replace strig in all files within a folder

Afan Pasalic afan at afan.net
Fri Jun 8 13:00:01 CDT 2012



On 6/8/2012 11:48 AM, Nicolai wrote:
> On Thu, Jun 07, 2012 at 06:35:21PM -0600, afan at afan.net wrote:
>> hi,
>> what would be the easiest but most simplest way to find and replace string
>> "foo" with "bar" in all files within a folder (and all sub-folders)?
>>
>> I found this
>> $find ./ -name "*.php" -exec sed -i "s/foo/bar/g" {} \;
>> and it works. But when I replace foo/bar with $_SESSION['status'] /
>> $_SESSION['value'] it doesn't work
> It's more informative to copy and paste output, rather than say it
> "doesn't work".
>
> Try this:
>
> sed 's/$_SESSION\['"'"'status'"'"'\] /$_SESSION\['"'"'value'"'"'\] /g' blah.php
>
> If that works on a single example file, you can plug the same logic into
> your find command.  Tested and works on OpenBSD/ksh and Linux/bash.
Yes, that's true I had to be more specific. When I mentioned "doesn't 
work" I meant nothing changed, but no error message as well.

I checked your line and it didn't work. Didn't do anything and no error 
message.
:(








More information about the Cialug mailing list