On Aug 15, 2007, at 6:45 PM, Dennis G. Wicks wrote:
Greetings;
I have, conservatively, dozens of html files to change.
I can find them and pass the file name to perl and
do the usual s/// changes but there is one change I can't
figure out.
There is a line in each file that looks like
<H1>This-Is-The-Title</H1>
of course, they are all different!
How can I change the hyphens to spaces in this line only?
Complicating the task is:
1. I don't know that there is only one such line per file.
I need to get them all.
2. I don't know that all <H1> are upper case.
3. Not all of the <H1> lines are the same record in the file.
I think this satisfies those constraints:
perl -0777 -pi.bak -we 's{(<h1>)(.*?)(</h1>)}{$x = $2; $x =~
tr:-: :; "$1$x$3"}geis' *.html
We slurp the file with -0777 to be able to work across lines (I
undestand (3) that way). Then we capture stuff between H1s case
insensitive, tr/// what's in between. Note that $n-variables are read-
only, that's why we copy the capture into a regular variable.
Of course that assumes a simple regexp is enough, you need to judge
whether that's the case in your data set.
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/