gpt4 book ai didi

regex - 搜索和替换哈希值。我究竟做错了什么?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:59 24 4
gpt4 key购买 nike

我在文件的开头有以下内容

<?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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com