I am trying to search for a pattern using SED and trying to replace some text (IP Address) after = which is in between of the line. But it is replacing till the end of the line where I need to ignore the last character in the line which is ".
This is my file where I need the update to be done on.
$ cat appsettings.json
......
..........
"ConnectionStrings": {
"PMIEnterpriseDbLocal":"Data Source=ec2-123-000-111-123.us-east-1.compute.amazonaws.com;Initial Catalog=FunnyTestDb;Persist Security Info=True;User ID=sa;Password=W@rld111"
},
......
.......
"Profile": "testing",
..............
.....
END OF FILE
I need 3 values to be replaced in the above file using SED.
Source = <someIP>
(should replace the IP till the ;)Password = <someText>
(should ignore the last character ")Profile = <someValue>
(should replace the value in the "")
I tried with the below commands to search for the 3 patterns:
sed -i -r 's#Source=[^ ;]*#Source=10.10.10.10#' appsettings.json"
SED used for Source pattern is working fine as expected (which mean I am able to replace the value with the provided IP address)
sed -i -r 's#Password=[^ ]*#Password=abc@123#' appsettings.json"
SED used for Password is working but the last character (which is ") in that line is also getting replaced, I only need the password to be replaced and last character (which is ") should be ignored.
sed -i -r 's#Profile:["^ "]*#Profile:"sample"#' appsettings.json"
SED should search for the pattern Profile in the file and replace the text which I pass
Expected executing the SED command, I should see the the updated appsetting file as below:
$ cat appsettings.json
......
..........
"ConnectionStrings": {
"PMIEnterpriseDbLocal":"Data Source=10.10.10.10;Initial Catalog=FunnyTestDb;Persist Security Info=True;User ID=sa;Password=abc@123"
},
......
.......
"Profile": "sample",
..............
.....
END OF FILE