I have to parse HTML to change text between two brackets that are not HTML code back to <
or >
.
Here an example of my HTML code that I have to replace:
<content:encoded><![CDATA[<div class="pre_headline">some text</div> <p>…. More text . </p><p></p><h2> More text </h2><p> More text < text between angle brackets > … more text
… </content:encoded>
desired output:
<content:encoded><![CDATA[<div class="pre_headline">some text</div> <p>…. More text . </p><p></p><h2> More text </h2><p> More text < text between angle brackets > … more text
… </content:encoded>
All the text is in one line. All the replacement I'm doing now is with sed or awk. But I couldn't figure out a way to replace the brackets in text without changing all the html tags.
I thought to define that all html brackets are not followed by a space. the inline text brackets are usually followed by a space. This could be a way to choose which brackets i have to replace. Maybe there is a better rule, since this method would not replace text in brackets without space :(
The following sed command would replace all brackets.
sed -e 's/>/\>/g' |
sed -e 's/</\</g' |
<
are good and which ones aren't. If they don't always have spaces around them, I don't see how anyone (including a human) can know which< >
to change and which to leave.