我正在尝试替换确切的字符串,但是我的sed命令返回错误。看来我的命令还没有被关闭
sed -i s/\<"rpc-whitelist-enabled">/\<"rpc-whitelist-enabled" : false,\>/g somefile
somefile
"rpc-whitelist": "127.0.0.1",
"rpc-whitelist-enabled": true,
错误
编辑:
此命令不会将值true
更改为false
cat file-name | sed s/"rpc-whitelist-enabled: true"/"rpc-whitelist-enabled : false"/g
某文件的内容:
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"cache-size-mb": 4,
"rpc-authentication-required": false,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-host-whitelist": "",
"rpc-host-whitelist-enabled": true,
"rpc-username": "",
"rpc-whitelist": "127.0.0.1",
"rpc-whitelist-enabled": true,
"scrape-paused-torrents-enabled": true,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"seed-queue-enabled": false,
"start-added-torrents": true,
}
答案 0 :(得分:1)
我不确定我是否能完全理解,但是尝试对您的数据进行了一些更改,但它似乎可以正常工作。如果您知道最重要的问题,请尝试解决
使用以下命令使用您的文件名
cat file-name | sed s/"rpc-whitelist-enabled: true"/"rpc-whitelist-enabled : false"/g
如果上述方法可行,请使用以下命令更新您的输入文件。用您的文件名更改文件名
sed -i s/"rpc-whitelist-enabled: true"/"rpc-whitelist-enabled : false"/g file-name
答案 1 :(得分:1)
您的sed有更多问题,请使用此问题:
sed -i '/"rpc-whitelist-enabled": true,/s/true/false/' somefile
测试:
$ cat somefile | sed '/"rpc-whitelist-enabled": true,/s/true/false/'
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"cache-size-mb": 4,
"rpc-authentication-required": false,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-host-whitelist": "",
"rpc-host-whitelist-enabled": true,
"rpc-username": "",
"rpc-whitelist": "127.0.0.1",
"rpc-whitelist-enabled": false,
"scrape-paused-torrents-enabled": true,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"seed-queue-enabled": false,
"start-added-torrents": true,
}