Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed replacement on multiple files 1

Status
Not open for further replies.

addinall

Programmer
May 7, 2008
2
AU
My brain seems to be stuck.

I got given some some 200 HTML files that had been
created on a Windows box using dreamweaver. After
hours of trying to figure out why my javascript
refuses to work (using the jQuery gear) I stumbled on
the fact that although all the input types had a name
allocated, none have an id.

What I want to do is use sed to search for

name="anythingatall"
and change it to
name="anythingatall" id="anythingatall"

I can't seem to get this one right.....

Mark.
 
Hi

Supposing the HTML looks like you posted :
Code:
sed '/<input/s/\(name="\([^"]*\)"\)/\1 id="\2"/' /path/to/input
If the tag or attribute names are not all lowercase ( not sure if it works in every [tt]sed[/tt] ) :
Code:
sed '/<input/Is/\(name="\([^"]*\)"\)/\1 id="\2"/i' /path/to/input
If the attribute values are not delimited with double quotes ( " ) then is abit more complicated.

Feherke.
 
Hi

Oops. Now I see that I forgot the last "if".

If there are more tags ( especially others than [tt]input[/tt] ) with [tt]name[/tt] attribute in one line then is abit even more complicated.

But I understand that is not the case.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top