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

Mike mike at linuxlychallenged.org
Fri Jun 8 09:10:53 CDT 2012


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
>
>




More information about the Cialug mailing list