Replace delimited block of text in file with the contents of another file

后端 未结 7 784
无人及你
无人及你 2020-12-09 06:32

I need to write a simple script to replace a block of text in a configuration file with the contents of another file.

Let\'s assume with have the following simplifie

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 06:45

    How about this little snippet I created:

    sed -n \
      -e "1,/<\!-- BEGIN realm -->/ p" \
      -e"/<\!-- END realm -->/,$ p" \
      -e "/<\!-- BEGIN realm -->/ r realm.xml" \
      server.xml
    

    The first commands prints the lines up to the second command prints the line starting at and the third commands append the text in the file 'realm.xml'. If only I could simplify the removing of the lines between and without removing the marker lines it would as simple as it gets. And it can be done inplace with sed!!!

提交回复
热议问题