trying to replace text patterns with dollar signs and ()s, can't get it to work. please help
find /var/www/vhosts/prod/xxx/ -name "*.php"|xargs perl -w -i -p -e "s/mysql_fetch_array\($res,MYSQL_ASSOC\)/mysql_fetch_assoc(\$res);/g"
trying to replace text patterns with dollar signs and ()s, can't get it to work. please help
find /var/www/vhosts/prod/xxx/ -name "*.php"|xargs perl -w -i -p -e "s/mysql_fetch_array\($res,MYSQL_ASSOC\)/mysql_fetch_assoc(\$res);/g"
I suspect that your shell is expanding $res
. Enclose the regex in single quotes to prevent this.
A slightly more efficient variation without xargs
and perl
:
find /var/www/vhosts/prod/xxx/ -name "*.php" -exec sed -i 's/mysql_fetch_array($res,MYSQL_ASSOC)/mysql_fetch_assoc($res);/g' {} \+
You also need to escape the $, ( and ) symbols in the search regex, you've already escaped the $ in the replacement string correctly.
With Perl 5.10.1 I have to use the -i.bak parameter to get this to work, otherwise the inplace edit switch complains that I don't have a backup.
find /var/www/vhosts/prod/xxx/ -name "*.php"|xargs perl -w -p -i.bak -e "s/mysql_fetch_array\(\$res,MYSQL_ASSOC\)/mysql_fetch_assoc(\$res);/g"