I am using this sed
command in particular file, but it doesn't work.
e.g.
a="adsfkndsa%/{}==admfkdsa"
b=sadkfjdsaklfj
sed -i -e 's/$a/$b/g' /tmp/sample.txt
Please suggest another way.
I am using this sed
command in particular file, but it doesn't work.
e.g.
a="adsfkndsa%/{}==admfkdsa"
b=sadkfjdsaklfj
sed -i -e 's/$a/$b/g' /tmp/sample.txt
Please suggest another way.
I just tried this, and it works on my system (Debian 8):
sed -i.bak "s|$a|$b|g" /tmp/sample.txt
You need to change the delimiter, since the variable $a
contains a /
.
Before:
cat /tmp/sample.txt.bak
foo
adsfkndsa%/{}==admfkdsa
bar
After:
cat /tmp/sample.txt
foo
sadkfjdsaklfj
bar
Edit, sed version info:
sed --version
sed (GNU sed) 4.2.2
sed -i -e 's/$a/$b/g"
, open with single quote and close with double quotes? – Sep 24 '16 at 06:33