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
you can use awk
awk 'FNR==NR{ _[++d]=$0;next}
/BEGIN realm/{
print
for(i=1;i<=d;i++){ print _[i] }
f=1;next
}
/END realm/{f=0}!f' realm.xml server.xml > temp && mv temp server.xml
realm.xml is passed to awk as the first file. FNR==NR means getting the records of the first file passed in and store to variable _. awk will process the next file once FNR!=NR. if awk finds /BEGIN realm/, print the BEGIN realm line, then print what is stored in _. By setting a flag (f) to 1, the rest of the lines after BEGIN realm will not be printed until /END realm/ is detected.