I have an HTML text file in this kind of format:
<html> ...etc... <pre> Line 1 Line 2 ...etc... Line n </pre> ...etc... </html>
I'd like to put a <p> tag at the end of each line which appears between the <pre> & </pre> tags, and finally remove the <pre> & </pre> tags, to give me this:
<html> ...etc... Line 1<p> Line 2<p> ...etc...<p> Line n<p> ...etc... </html>
I guess the simple and efficient way to do that would be to process the file line-by-line (and I might end up using such code), but first I'd like to see how it could be done treating the whole file as a single line. Here's the code I tried:
That works, except it strips the \n chars out like this of course:perl -0 -pe '1 while (s/(<pre>\n.*?)\n(.*<\/pre>)/$1<p>$2/ms);s/<\/?pr +e>//g' htmlfile
<html> ...etc... <pre> Line 1<p>Line 2<p>...etc...<p>Line n<p></pre> ...etc... </html>
So I tried this:
But that loops infintely because it keeps on matching "Line 1", which becomes "Line 1<p><p><p>...".perl -0 -pe '1 while (s/(<pre>\n.*?)\n(.*<\/pre>)/$1<p>\n$2/ms);s/<\/? +pre>//g' htmlfile
How can I concisely write such code, processing htmlfile as a single line?
Thanks...Terry
In reply to Substitution inside tags, as 1 line by tel2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |