Re: [arjunetal] Program that adds a phrase in footer of every page.
[In reply to]

Can't Post

Hi Arjun,

You are correct- you can easily do this in Perl!

There are a couple of ways you can do this:

1. process the file line by line (it's very easy, just use "open" and while (<FILEHANDLE>). Then check to see if the current line is equal to </body> (the code for this is "if ($line eq '</body>')..."). If it is, then print your header to the new file followed by the current input line; if it is not (ie, the if is false), then just print the current line to the input file.

2. you can use a "regular expression". If you do this, be sure to have the regex span over lines (there is some modifier).

I apologize for not writing the script for you, but this is really an excellent opportunity for you to start learning perl!!! I would suggest option 1 because that will teach you some good techniques. You should be able to get started just by doing some googling (ie. "perl read file"). And whenever you get stuck along the way, post on this forum what you have done and where you are stuck.

good luck! The more you teach me, the more I learn. The more I learn, the more I teach.

So exactly what I want is to add <p>How are you</p> before </body> tag.

This can be done very simply with biterscripting. (I had the same problem - wanted to insert copyright notices at the end of each page in tons of pages. Someone pointed me to biterscripting. It works great !) Here is a script. I will assume your html page is at C:/mysite/page.html.

Code

# Read in the page into a variable.

var str page ; cat "C:/mysite/page.html" > $page

# Insert "<p>How are you</p>\n" before "</body>".

sin -c "^</body>^l" "<p>How are you</p>\n" $page > $page

# Write page back.

echo $page > "C:/mysite/page.html"

You can also do this for all .html files in a folder (and subfolders). Use the following script.