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

后端 未结 7 810
无人及你
无人及你 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:55

    You may also use the ed command (cf. http://wiki.bash-hackers.org/howto/edit-ed ):

    cat <<-'EOF' | sed -e 's/^ *//' -e 's/ *$//' | ed -s server.xml
       H
       /BEGIN realm/i
       .
       /BEGIN realm/+1,/END realm/-1d
       .-1r realm.xml
       wq
    EOF
    

提交回复
热议问题