find and replace in every file under a root folder

C

Cortes

Suppose I want to add 1 single line:

<script src = "/sample.js" type="text/javascript"></script>

to every single webpage ( preferrably right after the tag <head>) under the
root folder called public_html in my server, i.e including all the webpages
in the subfolders as well. Suppose I have sample.js in public_html as well.

Can someone please spend some of your precious time to help me out with this
script because I know nothing about Perl but I really need the script. I've
done a search but no result.
Thanks very much in advance
 
G

Gunnar Hjalmarsson

Cortes said:
Suppose I want to add 1 single line:

<script src = "/sample.js" type="text/javascript"></script>

to every single webpage ( preferrably right after the tag <head>)
under the root folder called public_html in my server, i.e
including all the webpages in the subfolders as well. Suppose I
have sample.js in public_html as well.

Can someone please spend some of your precious time to help me out
with this script because I know nothing about Perl but I really
need the script. I've done a search but no result.

So you want to have that done. You don't know any Perl, but you still
know that you want a Perl script that does it.

Okay. These are two adequate routes to take:

1. Learn some Perl http://learn.perl.org/

2. Hire somebody who does it for you http://jobs.perl.org/
Thanks very much in advance

You're welcome.
 
J

Joe Smith

Cortes said:
Suppose I want to add 1 single line
to every single webpage ( preferrably right after the tag <head>) under the
root folder called public_html in my server, i.e including all the webpages
in the subfolders as well. Suppose I have sample.js in public_html as well.

Can someone please spend some of your precious time to help me out with this
script because I know nothing about Perl but I really need the script.

unix% find * -name '*.html' -print | xargs perl -pi.bak -e
's%(</head>)%$1<script src="/sample.js" type="text/javascript"></script>%i'

Or you could spend a few weeks learning the Perl language, then put that
one-liner into a program that uses the File::Find module.

-Joe

P.S. Next time, post to comp.lang.perl.misc instead of comp.lang.perl .
 
C

Cortes

Thanks to all,

Sorry that was the first time I was in comp.lang.perl. So i don't know where
to post it. I thought it would only take a few minutes if you know Perl.
Probly I was at the wrong place but thanks anyway, particularly Joe, I think
I've got it from what u wrote.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top