I have
in 3rd line of a file. I want to replace that with
. How to do this with sed
Each can be done with something similar to this:
sed -i "s/<\/host>/my_db<\/host>/" foo.txt
The -i
means that it'll overwrite the file in-place. Remove that flag to have the changes written to stdout.
If this is for a regular task to fill in details for the file, consider adding anchors to the file to make it easier. For example:
DB_HOST
Then the sed would just need to be:
sed -i 's/DB_HOST/my_db/'