用Apex charachter替代Sed

时间:2017-06-28 09:44:02

标签: regex sed apex

我正在尝试实施以下替换

sed -i 's/$config['default_host'] = '';/$config['default_host'] = 'localhost';/' /etc/roundcube/config.inc.php

但它不起作用。

我想要做的是将$config['default_host'] = '';替换为文件$config['default_host'] = 'localhost';内的/etc/roundcube/config.inc.php

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你应该转义特殊字符,因为sed$视为一行中字符的结尾

sed "s/\$config\['default_host'\] = '';/\$config['default_host'] = 'localhost';/" fileName

使用分组概念

sed "s/\(\$config\['default_host'\] = \)'';/\1'localhost';/" fileName

<强>输出:

$config['default_host'] =  'localhost';
相关问题