test.html:<html><body>
<div>
<div class="start">delete this</div>
</div>
<div><div class="start">delete this</div>leave this</div>
</body></html>
div.start and its content:
<div class="start">:
</div>. But we do not want to choose the wrong end pattern:
start and end pattern is always on single line.To do it so add "brake rule" (\n) on the left and right side of each
start patternTranslating to sed language:
Replace
<div class=\d034start\d034> with \n<div class=\d034start\d034>\nAdd the "brake rule" (\n) on the left and right side on
end pattern.Replace
<\/div> with \n<\/div>\nAt the end it looks like:
sed "s/<div class=\d034start\d034>/\n<div class=\d034start\d034>\n/g;s/<\/div>/\n<\/div>\n/g" test.html
sed "/<div class=\d034start\d034>/,/<\/div>/d":
sed ":a;N;$!ba;s/\n//g":
sed "s/<div class=\d034start\d034>/\n<div class=\d034start\d034>\n/g;s/<\/div>/\n<\/div>\n/g" test.html | sed "/<div class=\d034start\d034>/,/<\/div>/d" | sed ":a;N;$!ba;s/\n//g"
No comments:
Post a Comment