I am trying to replace a particular string in a file using the sed command. However, it is not working. Structure of data in my file:
"SomeServerName": {
"serverIP": "192.168.0.132",
"serverPort": "9999",
"active": false
}
In this, I want to change active status to true from false on the basis of IP which is a variable input I get from the terminal.
The sed command I have used is :
sudo sed -i "s/$someIP/!b;n;n;c\ \ \ \ \ \ \ \ "active": true/" filename
Here, $someIP=192.168.0.132. In sed, if I replace $someIP with '192.168.0.132' it works fine. However, if I pass the variable, it does not work.
EDIT: Below is my whole script for the above sed:
#! /bin/sh
someIP=$(hostname -I)
sudo sed -i "s/$someIP/!b;n;n;c\ \ \ \ \ \ \ \ "active": true/" filename