Inserting Lines into HTML Header

Discussion in 'HTML' started by Roy Schestowitz, Jun 12, 2005.

  1. 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>
    ....
    Roy Schestowitz, Jun 12, 2005
    #1
    1. Advertising

  2. On Sun, 12 Jun 2005 06:27:14 +0100, Roy Schestowitz <>
    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 |
    `-------------------------------------------------- --<--@ ------------'
    Barbara de Zoete, Jun 12, 2005
    #2
    1. Advertising

  3. Barbara de Zoete hastily replied:

    > On Sun, 12 Jun 2005 06:27:14 +0100, Roy Schestowitz
    > <> 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
    Roy Schestowitz, Jun 12, 2005
    #3
  4. Roy Schestowitz

    Toby Inkster Guest

    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
    Toby Inkster, Jun 12, 2005
    #4
  5. 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
    Roy Schestowitz, Jun 12, 2005
    #5
  6. On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
    <> 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
    William Hughes, Jun 12, 2005
    #6
  7. Roy Schestowitz

    Andy Dingley Guest

    On Sun, 12 Jun 2005 06:27:14 +0100, Roy Schestowitz
    <> wrote:

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


    Time to learn Perl.
    Andy Dingley, Jun 12, 2005
    #7
  8. William Hughes wrote:

    > On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
    > <> 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
    Roy Schestowitz, Jun 12, 2005
    #8
  9. Roy Schestowitz

    Mitja Guest

    On Sun, 12 Jun 2005 17:38:16 +0200, Roy Schestowitz
    <> wrote:

    >> On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
    >> <> 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
    Mitja, Jun 12, 2005
    #9
  10. Mitja wrote:

    > On Sun, 12 Jun 2005 17:38:16 +0200, Roy Schestowitz
    > <> wrote:
    >
    >>> On Sun, 12 Jun 2005 06:27:14 +0100, in alt.html Roy Schestowitz
    >>> <> 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
    Roy Schestowitz, Jun 13, 2005
    #10
  11. Roy Schestowitz

    Andy Dingley Guest

    On Mon, 13 Jun 2005 04:03:52 +0100, Roy Schestowitz
    <> wrote:

    >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.
    Andy Dingley, Jun 13, 2005
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mlt
    Replies:
    2
    Views:
    832
    Jean-Marc Bourguet
    Jan 31, 2009
  2. Replies:
    6
    Views:
    1,209
    David Thompson
    Dec 14, 2010
  3. Replies:
    7
    Views:
    177
    Ben Morrow
    Jun 7, 2006
  4. Ciba LO
    Replies:
    4
    Views:
    182
    Ciba LO
    Jul 8, 2006
  5. ste-m
    Replies:
    1
    Views:
    315
Loading...

Share This Page