Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Inserting Lines into HTML Header

Reply
Thread Tools

Inserting Lines into HTML Header

 
 
Roy Schestowitz
Guest
Posts: n/a
 
      06-12-2005
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>
....
 
Reply With Quote
 
 
 
 
Barbara de Zoete
Guest
Posts: n/a
 
      06-12-2005
On Sun, 12 Jun 2005 06:27:14 +0100, Roy Schestowitz <(E-Mail Removed)>
wrote:

> 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 |
`-------------------------------------------------- --<--@ ------------'

 
Reply With Quote
 
 
 
 
Roy Schestowitz
Guest
Posts: n/a
 
      06-12-2005
Barbara de Zoete hastily replied:

> On Sun, 12 Jun 2005 06:27:14 +0100, Roy Schestowitz
> <(E-Mail Removed)> wrote:
>
>> 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.


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

--
Roy S. Schestowitz
http://Schestowitz.com
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      06-12-2005
Roy Schestowitz wrote:

> 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

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
Roy Schestowitz
Guest
Posts: n/a
 
      06-12-2005
Toby Inkster wrote:

> Roy Schestowitz wrote:
>
>> 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


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<&-


--
Roy S. Schestowitz
http://Schestowitz.com
 
Reply With Quote
 
William Hughes
Guest
Posts: n/a
 
      06-12-2005
On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
<(E-Mail Removed)> wrote:

> 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:


Xchange: http://www.simes.clara.co.uk/programs/xchange.htm


 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-12-2005
On Sun, 12 Jun 2005 06:27:14 +0100, Roy Schestowitz
<(E-Mail Removed)> wrote:

>Can anybody recommend a simple program/script that will insert given (input)
>lines to a HTML header?


Time to learn Perl.

 
Reply With Quote
 
Roy Schestowitz
Guest
Posts: n/a
 
      06-12-2005
William Hughes wrote:

> On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
> <(E-Mail Removed)> wrote:
>
>> 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:

>
> Xchange: http://www.simes.clara.co.uk/programs/xchange.htm


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
 
Reply With Quote
 
Mitja
Guest
Posts: n/a
 
      06-12-2005
On Sun, 12 Jun 2005 17:38:16 +0200, Roy Schestowitz
<(E-Mail Removed)> wrote:

>> On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
>> <(E-Mail Removed)> wrote:
>>
>>> 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

>
> 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
 
Reply With Quote
 
Roy Schestowitz
Guest
Posts: n/a
 
      06-13-2005
Mitja wrote:

> On Sun, 12 Jun 2005 17:38:16 +0200, Roy Schestowitz
> <(E-Mail Removed)> wrote:
>
>>> On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
>>> <(E-Mail Removed)> wrote:
>>>
>>>> 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

>>
>> 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.


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

>> 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


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

Roy

--
Roy S. Schestowitz
http://Schestowitz.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting IPv4 header checksum into dummy IP header lancer6238@yahoo.com C Programming 6 12-14-2010 05:00 AM
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Inserting Page Load Times into HTML Source as a HTML Comment ste-m Javascript 1 11-01-2006 03:18 AM
How to break the lines in printing to html lines? Ciba LO Perl Misc 4 07-08-2006 02:58 AM
Inserting lines into text files, or howto "fix" vCards having no n: entry analogquack@gmail.com Perl Misc 7 06-07-2006 08:59 PM



Advertisments