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

后端 未结 7 783
无人及你
无人及你 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 07:01
    TOTAL_LINES=`cat server.xml | wc -l`
    BEGIN_LINE=`grep -n -e '<!-- BEGIN realm -->' server.xml | cut -d : -f 1`
    END_LINE=`grep -n -e '<!-- END realm -->' server.xml | cut -d : -f 1`
    TAIL_LINES=$(($TOTAL_LINES-$END_LINE))
    
    head -n $BEGIN_LINE server.xml > server2.xml
    cat realm.xml > server2.xml
    tail -n $TAIL_LINES server.xml > server2.xml
    

    (OK, this does not use awk or sed... I assumed that was not an exclusive requirement :-)

    0 讨论(0)
提交回复
热议问题