1

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.

Ketan
  • 9,226
user191625
  • 11
  • 3

1 Answers1

3

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