I'm trying to replace two strings in a php file using two sed commands, can't find where I'm wrong.
Want to transform from strings
setlocale(LC_ALL, $_COOKIE['lang']);
and
putenv("LANGUAGE=".$_COOKIE['lang']);
to the strings
setlocale(LC_ALL, $_COOKIE['lang'].'.utf8');
and
putenv("LANGUAGE=".$_COOKIE['lang'].'.utf8');
so far I've come to the following but does not work
sed -i "s/setlocale\(LC_ALL, \$_COOKIE\['lang'\]\);.*$/setlocale\(LC_ALL, \$_COOKIE\['lang'\]\.'\.utf-8'\)\;/" file.php
sed -i "s/putenv\('LANGUAGE='\.\$_COOKIE\['lang'\]\);.*$/putenv\('LANGUAGE='\.\$_COOKIE\['lang'\]\.'\.utf-8'\)\;/" file.php
I'm definitely not an expert in sed and regular expression, so go easy on me ok?
Try these two:
sed 's/setlocale.LC_ALL, ._COOKIE..lang...;/setlocale\(LC_ALL, $_COOKIE\['\''lang'\''\].'\''.utf8'\''\);/g' file.php
sed 's/putenv..LANGUAGE...._COOKIE..lang...;/putenv\("LANGUAGE=".$_COOKIE\['\''lang'\''].'\''.utf8'\'');/g' file.php
You should not escape the parentheses. There is no need to escape matching characters in the replacement part, either:
sed "s/setlocale(LC_ALL, \$_COOKIE\['lang'\]);.*$/setlocale(LC_ALL, \$_COOKIE['lang'].'.utf-8')\;/"
The putenv
line contains double quotes, but your expressions searches for single quotes. Therefore, it cannot match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With