0

This question already has an answer here:

I am trying to replace matching string with other string. This is what I have

ZKHOSTS="host1,host2,host3"
old_string="tsd.storage.hbase.zk_quorum*"
new_string="tsd.storage.hbase.zk_quorum = $ZKHOSTS"

sed -i '/$old_string/c\$new_string' /etc/opentsdb/opentsdb.conf

which isn't working as excepted.

I even tried following

sed -i 's/$old_string/$new_string/g' /etc/opentsdb/opentsdb.conf

sed -i '/${old_string}/${new_string}/g' /etc/opentsdb/opentsdb.conf

I dont know what wrong I am doing here.

marked as duplicate by Eric Renouf, Archemar, steeldriver, GAD3R, Anthon Sep 27 '16 at 15:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You must use double quotes, like:

sed -i "s/$old_string/$new_string/g" /etc/opentsdb/opentsdb.conf

Not the answer you're looking for? Browse other questions tagged or ask your own question.