i have one variable e.g.
var1="<envpath>/home/genl/jeenk[path]/OT/</envname>"
and having <envpath>/home/genl/jeenk[path]/OT/</envname>
entry in
file.txt
but if i try to change this by using sed command its not changed.
e.g.
sed -i "s|$var1|/home/genk/g" file.txt
what could be the solution to this, to escape [
&
]
in var
?
-bash-4.4$ var1=$(echo "${var1/]/\\]}") -bash-4.4$ echo $var1 /home/genl/jeenk\[path\]/OT -bash-4.4$
You may use both substitution for opening & closing brackets before applying to you sed command – francois P Jan 22 '18 at 19:50