Thursday, February 17, 2022

[SOLVED] sed command seems unfinished

Issue

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,
}

Solution

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,
}


Answered By - Kubator
Answer Checked By - Dawn Plyler (WPSolving Volunteer)