I have markdown README file that have html markers like this:
<!-- CONTRIBUTORS-START -->
<!-- CONTRIBUTORS-END -->
and I want to replace the text inside (it may already have stuff) with new content from a file that have html tags and newline characters (it's markdown table with html in cells).
I was trying to replace newlines by 0xFF do sed and after replace it back using this code:
CONTRIBUTORS=`./contributors -u jcubic -r jquery.terminal -m | tr '\n' $'\xFF'`
# contributors script get data from github and display markdown table
# or ERROR if rate limit reached
echo "$CONTRIBUTORS" | grep ERROR > /dev/null || cat README.in | tr '\n' $'\xFF' | \
sed -e "s%\(<!-- CONTRIBUTORS-START -->\).*\(<!-- CONTRIBUTORS-END -->\)%\1\n${CONTRIBUTORS}\2%" #| tr $'\xFF' '\n'
but this don't work, how can I replace text inside markers with CONTRIBUTORS content?
It was kind of working when I use tr '\n' '\xFF'
but it was replacing newline by x
.
I found this article Sed: Mutli-Line Replacement Between Two Patterns and try it using:
sed -n "/CONTRIBUTORS-START/{p;:a;N;/CONTRIBUTORS-END/!ba;s%.*\n%${CONTRIBUTORS}\n%};p"
(I've replaced / by % in s command) but got error:
sed: -e expression #1, char 1630: unterminated `s' command