editing single line in html file in perl script

Hi Folks,

It is regarding the perl scripting.

I have an html file(many files) which contains the below line in the body tag.

<body>
<P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P>
</body>

Now I want to read that html file through perl script and edit the html file by changing the text from Hello to Hello Giridhar and the other text remains same.This tag is in exactly 8th line in the html file

After running the scipt, if I open the html file than the text "Hello Giridhar" has to be displayed instead of Hello.

Could you please share your ideas on this ?

Thanks in advance..

Regards,
Giridhar

Hi

$ perl -pne 's/Hello/Hello Giridhar/ if($.==8)' file

Guru

1 Like

Many thanks Guruprasad...

I do have a small change here..
In my perl script, the name keeps on changing in the loop based on the parameters passed to the script.

Could you please let me know the code based on the above condition.

Regards,
Giri

@guruprasadpr: Option n is not required if p is used. In crude terms, Option p = Option n + print.

@giridhar276:Here's a bash script:

#! /bin/bash

for htmlFile in *.html
do
    sed -i "8s/Hello/$1/" $htmlFile
done

To run, give the name as argument to script

$ ./test.sh Giridhar
1 Like