SED - AWK - Replace Section Within File

Here is how to replace a multiline text between two tags or lines of text with awk or sed.

File: 'test'

###START
1
2
###STOP

SED:

sed -i -e "/START\$/,/STOP\$/c START\n${REPLACEMENT}\nSTOP" test

AWK:

awk "/START/{p=1;print\"#START\n${REPLACEMENT}\n#STOP\";next}/STOP/{p=0;next}!p" test.tmp > test

Note: test must be copied to test.tmp before replacement can be done.