0

I'm trying to replace an exact string but my sed command is returning an error. Looks like my comand isn't closed propery

sed -i s/\<"rpc-whitelist-enabled">/\<"rpc-whitelist-enabled" : false,\>/g somefile

somefile

"rpc-whitelist": "127.0.0.1",
"rpc-whitelist-enabled": true,

Error

error

EDIT:

This command won't change the value true into false

cat file-name | sed  s/"rpc-whitelist-enabled: true"/"rpc-whitelist-enabled : false"/g

Content of somefile :

{
    "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,
}
executable
  • 3,365
  • 6
  • 24
  • 52

2 Answers2

1

I am not sure if I understood exactly but tried with your data with some changes and it seems to be working. Let if you know any issue on top of that, will try to fix it

use below command using your file-name

cat file-name | sed s/"rpc-whitelist-enabled: true"/"rpc-whitelist-enabled : false"/g

if above works, use below command to update your input file. change file-name with your file-name

sed -i s/"rpc-whitelist-enabled: true"/"rpc-whitelist-enabled : false"/g file-name

  • which os are you using ? can you share exact error message , because I have tested it before sharing with you –  Nov 22 '18 at 13:48
  • If you have no erros, that means its working, but not matching what its trying to match. So using above command which start with cat, try to narrow down criteria,and check few times. You will know what exactly is not matching , and we will find the solution –  Nov 22 '18 at 13:51
  • Nop, because the value doesn't change – executable Nov 22 '18 at 13:58
  • cat file-name | sed 's/\"rpc-whitelist-enabled\": true/\"rpc-whitelist-enabled\" : false/g' –  Nov 22 '18 at 14:04
1

There are more issues with Your sed, rather use this one:

sed -i '/"rpc-whitelist-enabled": true,/s/true/false/' somefile

Test:

$ 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,
}
Kubator
  • 1,373
  • 4
  • 13