Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 转义SED命令_Php_Linux_Sed_Escaping - Fatal编程技术网

Php 转义SED命令

Php 转义SED命令,php,linux,sed,escaping,Php,Linux,Sed,Escaping,我试图运行一个脚本来替换大量.php文件中的一段代码。我需要替换: `popupOpen(\'/home/open.php?c='.urlencode($row['id']).'&s=\', 650, 600)` 为此: `popupOpen(\'/home/open.php?c='.urlencode($row['id']).'&s=\', 1024, 750)` 我使用的命令是: find . -name "index.php" -print | xargs sed -

我试图运行一个脚本来替换大量.php文件中的一段代码。我需要替换:

`popupOpen(\'/home/open.php?c='.urlencode($row['id']).'&s=\', 650, 600)` 
为此:

`popupOpen(\'/home/open.php?c='.urlencode($row['id']).'&s=\', 1024, 750)`
我使用的命令是:

find . -name "index.php" -print | xargs sed -i "s/popupOpen(\\\'\/home\/open.php?c='.urlencode\($row\['id']\).'\&s=\\\', 650, 600)/popupOpen(\\\'\/home\/open.php?c='.urlencode\($row\['id']\).'\&s=\\\', 1024, 750)/g"

我似乎无法逃脱。我缺少什么?

您可以不使用
xargs

find .name "index.php" -exec sed -i '' sed "whatever" {} \;
在这种情况下,我认为这会起作用:

find . -name "index.php" -exec sed "s|popupOpen(\\\\'/home/open\.php\?c=\'\.urlencode(\\\$row\[\'id\'\])\.\'&s=\\\\', 650, 600)|popupOpen(\\\\'/home/open\.php\?c=\'\.urlencode(\\\$row\[\'id\'\])\.\'\&s=\\\\', 1024, 750)|g" {} \;

你说有很多文件,但你只是在寻找
index.php
我将在其中运行该命令的文件夹大约有120个,每个文件夹都有index.php。在我看来,你只需要将650替换为1024,将600替换为750,我可以缩短该命令使其更简单,但是我想知道,如果将来我不得不运行类似的命令,那么需要转义什么,可能会更复杂。您还需要转义
$
,ohterwise
$row
将由shell展开(可能是空字符串)。。。也许你应该考虑把SED脚本放进一个文件中,并用<代码> SED-F脚本< /代码>调用它。让逃跑变得容易一点。