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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace specific line of files with "some expression"

Status
Not open for further replies.

starlite79

Technical User
Aug 15, 2008
89
US
Hi,

I have some webpages that I built using a template. The first 38 lines of each html file are the same. I'd like to use Perl to change line 38 to say <div id = "body" class="clearfix"> (It currently is <div id="body">)

I was thinking of trying this:
Code:
perl -ple '$_ = "<div id=\"body"\ class=\"clearfix"\>" if $. == 38; close ARGV if eof' *.html

Is the syntax right for using literal quotes and such?
 
Did you mean to use -pie?

You need to put your escapes (i.e. backslashes) before each double-quote... not surround them in backslashes. e.g. id=\"body\" instead of id=\"body"\. Backslash always escapes the character immediately following it.

Annihilannic.
 
Hi

starlite79 said:
change line 38 to say <div id = "body" class="clearfix"> (It currently is <div id="body">)
[tt][small][blue][ignore][off-topic][/ignore][/blue][/small][/tt]
I would just copy the .clearfix rules into the #body style definition in the CSS.
[tt][small][blue][ignore][/off-topic][/ignore][/blue][/small][/tt]
Annihilannic said:
Did you mean to use -pie?
If yes, he probably means -pi -e.

Feherke.
 
Thanks for the help. Sorry for the late response, but I was away from my computer for a week.

This seemed to do what I wanted (I wanted to replace line 38)
Code:
perl -i -ple '$_ = "<div id=\"body\" class=\"clearfix\">" if $. == 38; close ARGV if eof' *.html

It's actually what she meant; just to clarify :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top