Unix Shell - [newbiew]removing attributes of html element?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > [newbiew]removing attributes of html element?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author [newbiew]removing attributes of html element?
Tony Winslow

2007-12-09, 7:34 am

Hi, all! I'm new here.

How can I remove attributes of a html element using a shell script?
i.e.
change
"<table border=1><tr>a</tr></table>"
into
"<table><tr>a</tr></table>"
And if I want to find the answer in google, what keywords should I use?

Thank you in advance!
Janis Papanagnou

2007-12-09, 1:25 pm

Tony Winslow wrote:
> Hi, all! I'm new here.
>
> How can I remove attributes of a html element using a shell script?
> i.e.
> change
> "<table border=1><tr>a</tr></table>"
> into
> "<table><tr>a</tr></table>"
> And if I want to find the answer in google, what keywords should I use?
>
> Thank you in advance!


sed 's/ border=[0-9]*//g' yourfile.html >newfile.html

But there may/should be quotes around the attribute value, so maybe
one of the following may be more appropriate...

sed 's/ border="[^"]*"//g' yourfile.html >newfile.html
sed "s/ border='[^']*'//g" yourfile.html >newfile.html

Or even

sed '/<table/s/ border="[^"]*"//g' yourfile.html >newfile.html


Janis
Ed Morton

2007-12-09, 1:25 pm



On 12/9/2007 7:10 AM, Tony Winslow wrote:
> Hi, all! I'm new here.
>
> How can I remove attributes of a html element using a shell script?
> i.e.
> change
> "<table border=1><tr>a</tr></table>"
> into
> "<table><tr>a</tr></table>"
> And if I want to find the answer in google, what keywords should I use?
>
> Thank you in advance!


If the attributes have to be on the same line as the tag, then:

sed 's/\(<[^ ]*\)[^>]*>/\1>/g' file

Ed.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com