Say I have a text file like this:
# custom content section
a
b
### BEGIN GENERATED CONTENT
c
d
### END GENERATED CONTENT
I'd like to replace the portion between the GENERATED CONTENT
tags with the contents of another file.
What's the simplest way to do this?
Answer
newContent=`cat new_file`
perl -0777 -i -pe "s/(### BEGIN GENERATED CONTENT\\n).*(\\n### END GENERATED CONTENT)/\$1$newContent\$2/s" existing_file
No comments:
Post a Comment