This question already has an answer here:
I need to replace current value in configuration file with new value which is assigned to variable ,
like
file_name=abc.txt
needs to be replaced like
file_name=xyz.txt
where $file=xyz.txt
I tried
sed -i 's/file_name=.*/file_name=$file/g' conf_file.conf
however the variable is not getting expanded,
it comes like file_name=$file
.
any pointers?
This should work,assuming that variable
file
has value:xyz.txt
assigned to it:Output:
file_name=xyz.txt