2013-04-12 91 views
0

我想运行一个脚本来替换很多.php文件中的一段代码。我需要更换:转义SED命令

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

我只是不能似乎正确地逃避它。我错过了什么?

+1

你说的文件很多,但你只是寻找'index.php' –

+0

我将在哪里运行该命令,每个文件夹都带有index.php约120个文件夹。 – Sean

+0

它在我看来只需要用1024和600替换650用750 – poiu2000

回答

0

你可以不使用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" {} \;