I'm attempting to find/replace a string found in a number of files spread throughout a directory tree.
I thought I'd use sed for this task.
find /some/dir -name \*.php -exec sed -i "s/cybernetnews/cybernet/g" {} \;
This works as expected with the sample string "cybernetnews", but things get weird when I try to find/replace against this string:
preg_match($_SESSION['infos']['num'], $numeric_variable)
Where I want to replace the string $_SESSION['infos']['num']
with the constant INFOS_NUM
.
So I thought this would work:
find /some/dir -name \*.php -exec sed -i "s/$_SESSION['infos']['num']/INFOS_NUM/g" {} \;
No luck, here is what shows in the test php file after running the above command:
preg_match($_SESSION['INFOS_NUMfoINFOS_NUM][INFOS_NUMum'],
$INFOS_NUMmeric_variable)
I tried escaping the single quote but get the exact same result. If I escape the bracket, no changes are made.
What character(s) is sed
getting hung up on, and how do I properly escape it?