I have a file containing data with the following format:
{"parameter":"toto.tata.titi", "value":"0/2", "notif":"1"}
I make a change on the file with sed:
sed -i "/\<$param\>/s/.*/$line/" myfile
which line
variable is
{"parameter":"toto.tata.titi", "value":"0/2", "notif":"3"}
and param
variable is toto.tata.titi
The above sed
command return error:
sed: unmatched '/'
Because the line
variable is containing /
==> "0/2"
How to update my sed command to make it work even if the line
variable is containing /
?
This will robustly only operate on lines containing the string (not regexp)
toto.tata.titi
:and will be unaffected by any chars in
param
or inline
other than backslashes. If you need to be able to process backslashes as-is, the shell variables just need to be moved to the file name list and the awk variables populated from them in the BEGIN section instead of by-v
assignment:Your
$param
or$line
may contain / on it which causessed
to have a syntax error. Consider using other delimiters like|
or@
.Example:
But that may not be enough. You can also quote your slashes when they expand:
Other safer characters can be used too: