On Aug 15, 12:45 pm, [EMAIL PROTECTED] (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.
Untested: perl -lpi.bkp -e' if (m!(<h1>(?:[a-z]+-)+[a-z]+</h1>)!i) { #if the pattern is found on this line $h1_sec = $1; #save the offending pattern ($mod_sec = $h1_sec) =~ tr/-/ /; #change the dashes to spaces s/$h1_sec/$mod_sec/; #replace the pattern found with the modified version } ' file1.html file2.html file3.html This should find all instances of your pattern in each file, with the exception of more than one instance of the pattern on the SAME line of the SAME file. If that's a possibility, you'd have to make it more complicated, putting a foreach loop around the whole thing, making the first pattern match globally.... Hope that helps, Paul Lalli Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/