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

Afan Pasalic afan at afan.net
Fri Jun 8 09:16:24 CDT 2012


When I need to be done any solution is acceptable :)
Linux, OS X, Win. (No BSD though...)
If there is an application to do this it's fine too. I just have to be 
done. :)


On 6/8/2012 9:10 AM, Mike wrote:
> OP: Though this is a Linux board many people run Mac so, just in case. 
> Are you running Linux, BSD, or OS X?
>
> BSD versions of *sed* are different than the GNU versions. I had this 
> issue when helping a friend with a like issue just last week.
>
> M
>
>
> On 6/7/2012 7:35 PM, 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
>>
>> when run
>> $find ./ -name "*.php" -exec sed -i
>> "s/$_SESSION['status']/$_SESSION['value']/g" {} \;
>> it replaced almost everycharacter with ['value'] :)
>>
>> when tried
>> $find ./ -name "*.php" -exec sed -i
>> "s/\$_SESSION['status']/\$_SESSION['value']/g" {} \;
>> didn't do anything
>>
>> suggestions?
>>
>> thanks.
>>
>>
>> _______________________________________________
>> Cialug mailing list
>> Cialug at cialug.org
>> http://cialug.org/mailman/listinfo/cialug
>>
>>
>
>
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug


More information about the Cialug mailing list