作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在文件的开头有以下内容
<?php
return array(
'DB' => array(
'extTablesDefinitionScript' => 'extTables.php',
'host' => '172.17.1.47',
172.17.1.47
可以是任何东西。我想将它的设置更改为 $ip
中的内容。所以我试过了
ip="1.2.3.4"
sed -i "s/\'host\' => \'.*\',/$ip/g" /tmp/LocalConfiguration.php
sed -i "s/\(\'host\' => \'\).*/\1$ip\'/g" /tmp/LocalConfiguration.php
但这并没有改变任何东西。
问题
谁能看出哪里出了问题?或者知道更好的方法吗?
最佳答案
引用似乎搞砸了。您可以使用:
ip="1.2.3.4"
sed -i.bak -r "s/('host' => ')[^']*'/\1$ip'/" file.php
cat file.php
<?php
return array(
'DB' => array(
'extTablesDefinitionScript' => 'extTables.php',
'host' => '1.2.3.4',
关于regex - 搜索和替换哈希值。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29370788/
我是一名优秀的程序员,十分优秀!