Inserting Lines into HTML Header

R

Roy Schestowitz

Can anybody recommend a simple program/script that will insert given (input)
lines to a HTML header? I need this to operate on a large number of files,
so, as a simplistic example, if I have N files containing:

<html>
<head>
</head>
....

they should be converted into:

<html>
<head>
<title>My Title</title>
</head>
....
 
B

Barbara de Zoete

Can anybody recommend a simple program/script that will insert given (input)
lines to a HTML header? I need this to operate on a large number of files,
so, as a simplistic example, if I have N files containing:

<html>
<head>
</head>
...

they should be converted into:

<html>
<head>
<title>My Title</title>
</head>
...

A page title should be a _page_ title. I don't see how inserting one specific
title into N pages is any good.

Anyway, most good text editors will do this for you with a search and replace.

--
,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
| weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
| webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
|zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
`-------------------------------------------------- --<--@ ------------'
 
R

Roy Schestowitz

Barbara de Zoete hastily replied:
A page title should be a _page_ title. I don't see how inserting one
specific title into N pages is any good.

Anyway, most good text editors will do this for you with a search and
replace.

I stressed that it was "a simplistic example". It is the principle that I'm
after.

"Search and replace" in text editors won't do because I deal with many
files. If there exists a command-line tool that will add string X after a
regular expression Y is detected, _and_ apply this to /all/ files, then I'd
be a happy puppy. I am sure there is something out there already so I
decided to ask the gurus.

Roy
 
T

Toby Inkster

Roy said:
If there exists a command-line tool that will add string X after a
regular expression Y is detected, _and_ apply this to /all/ files, then
I'd be a happy puppy.

sed -i 's/<head>/<head><title>Hello World<\/title>/i;' *.html
 
R

Roy Schestowitz

Toby said:
sed -i 's/<head>/<head><title>Hello World<\/title>/i;' *.html

Thanks a bunch Toby! Somehow I knew you'd be the most suitable person to
help.

Along with the following I can now manipulate things the way I wanted.

exec 3<&0
find . -type d -print |
while read dirname
do
(cd $dirname
exec 0<&3
"$@"
)
done
exec 3<&-
 
R

Roy Schestowitz

William said:

That seems like what I was after, but it's for Windows and it's commercial.

I have now sorted out everything I needed to (I haven't managed to see
messages later than Toby's). I added an RSS feed link to the header of all
static pages of my site (they are static because Perl generates them
off-line).

If anybody is interested in the scripts, I have documented everything at the
following address: http://www.schestowitz.com/util.htm#search_and_replace

Roy
 
M

Mitja

I added an RSS feed link to the header of all static pages of my site
(they are static because Perl generates them
off-line).

You're already familiar with perl? Then say so! :)
Sed is fine, but I guess in your case you'll prefer perl. Google for perl
-pi -e trick.
If anybody is interested in the scripts, I have documented everything at
the following address:
http://www.schestowitz.com/util.htm#search_and_replace

Mine is shorter and hardly needs its own page:
perl -pi -e 's/olde text/new text/' `find . -name \*.html`

Talk about elegant ;)

Mitja
 
R

Roy Schestowitz

Mitja said:
You're already familiar with perl? Then say so! :)
Sed is fine, but I guess in your case you'll prefer perl. Google for perl
-pi -e trick.

I can read Perl, understanding what it does by relying on context. I can't
quite write Perl because I never learned it.
Mine is shorter and hardly needs its own page:
perl -pi -e 's/olde text/new text/' `find . -name \*.html`

Talk about elegant ;)

*smile* You'll shatter my confidence. Don't show me the back door after I
dynamited the main gate...

Roy
 
A

Andy Dingley

I can read Perl, understanding what it does by relying on context. I can't
quite write Perl because I never learned it.

Odd -- Most of us can write it, but can't read it afterwards.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top