Substitution on range of lines

后端 未结 4 2059
独厮守ぢ
独厮守ぢ 2021-01-26 16:58

I have in 3rd line of a file. I want to replace that with my_dB. How to do this with sed

4条回答
  •  独厮守ぢ
    2021-01-26 17:29

    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/'
    

提交回复
热议问题