Linux Rocks ! wrote:

>       I do have a question about grep and stuff... I would like to
> replace text with different text (like change alt= tags to title= or
> duplicate alt tags to title tags... so, If i have something like
> 
> <a href="www.rocksolidnetworks.com"><img src="rock.jpg" alt="picture of 
> rock"></a>
> 
> and I want
> 
> <a href="www.rocksolidnetworks.com"><img src="rock.jpg" alt="picture of rock"
> title="picture of a rock"></a>
> 
> What is the easiest way (yes, I could read awk, and sed and grep...) but I 
> basicly just want a rename for inside files (not just filenames).

*The easiest* way it to say, "Hey, Seth, can you change some web pages
for me?"  That's not very fast -- it may take several weeks, depending
on how many S+++++'s you have in your EUGLUG code.

*The second easiest* way is something like this.

Dup alt tag to title tag:

        find /var/www/htdoc -type f | xargs perl -p -i.orig -e \
            's/alt\=\"([^\"]*)\"/alt="$1" title="$1"/gi'

Replace alt tag w/ title tag:

        find /var/www/htdoc -type f | xargs perl -p -i.orig -e \
            's/alt\=\"([^\"]*)\"/title="$1"/gi'

That isn't smart enough to check that that alt tag is inside an
<img> directive or inside any directive, for that matter.

But this is...

        s/\<img [^\>]*alt=\"([^\"]*)\"/title="$1"/gis

Note the "s" character at the end.  It makes the whole thing
work even if the tag spans multiple lines.

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     [EMAIL PROTECTED]

Reply via email to