How to join several HTML files?

Hello
I need to merge several HTML files into one and possibly convert it to ".rtf"
All files are in the same folder.
The files contain Links I need to keep
Any hints?
Thanks

We need a little more info. Do they contain scripts? The same script(s)? Styles? Is everything within the "body" shown with the same attributes? If they contain tables would you keep them separate or combine them?

You can look at the source behind an HTML file by opening it up with a text editor or, if you are already using a browser to look it it, Ctrl/U can bring it up.

Learn as much as you can about HTML -- that should go a long way in seeing how to combine them.

In any web page there is only one "html", "head", "title", and "body". Those are enclosed in less-than and greater-than symbols instead of quotes and a slash before those (or any other html structures) names will turn off or end it.

That should get you started.

1 Like

Is all rather complex .... I am a MAC user and everything here is Mac related.
i generate a number of pages from a database application DVDpedia frm bruji.com
each pages follows the same format:
the app uses my HTML template filling it up with data if the various fields are populated in the original db else skipping them if they are empty.
My tables tables are only "cosmetic"
I need to join the pages as in certain cases they are up to 120 I hope to find an automated way to join them as they all are in one specific folder.
I created this template and it works perfectly returning all the data I need to then post on my site where my students find information.
However I still need the single Html file if possible so I can open it in TextEdit or MicrosoftWord to do some additional work.
the first attachement is a template I created using the db software (DVDPEDIA) rules
the following attachments are some randomly choosen resulting files
Regards and thanks

I haven't looked at it in detail, but it seems you should first make a copy of your Europe page first. Next go through your other pages and copy from your first MOVIE starting with the tag just in front of it down to just in front of (/body)

You would use </body>, not parentheses like in the "(/body)" example

of page1 and copy it just in front of Europe's (/body). See what it looks like in a browser to decide if that works before copying the other pages in.

HTH

P.S. One more resource:HTML- Webdeveloper.com

HTML-documents follow a certain structure:

<HTML>
     <HEAD>
          ....all sorts of text, META-tags, etc. ...
     </HEAD>
     <BODY>
          ....all sorts of text, the real content of your document ...
     </BODY>
</HTML>

In a first step I'd start to extract everything within the <body>...</body> -tags (the "content" in a narrower sense) and put that into into one document, like that:

<HTML>
     <HEAD>
          ...maybe use the content fo the HEAD-tag from the first document here..
     </HEAD>
     <BODY>
          ....everything between the BODY-tags from the first document....
          ....everything between the BODY-tags from the second document....
          ....everything between the BODY-tags from the third document....
          ...
     </BODY>
</HTML>

Here is a script that should do that. Note that it might fail because to fully "understand" HTML as a language it would have to use a recursive parser, which is too much effort to put it into a casual solution here. It should provide a starting point for you, though.

Note that you might want to refine especially the parameter handling, right now it uses the bare minimum. The same goes for error handling (mistyped file names, ...). Call it like:

$ script file1 file2 file3 .... > outputfile
#! /bin/ksh

typeset    fIn=""                        # input filename
typeset -i lFirst=1                      #  flag for first file

while [ -n "$1" ] ; do
     fIn="$1"                            # get next file from input
     shift

     if (( lFirst )) ; then              # first file is copied up to "</body>"
          sed '/<\/body>/ {
                    s/<\/body>.*//
                    :loop
                       n
                       /.*/d
                    b loop
                    }' "$fIn"
          lFirst=0
     else
                                         # subsequent files, only the content
                                         # of "<body>...</body>"
          sed -n '/<body>/,/<\/body>/ {
                        /<body>/ s/.*<body>//
                        /<\/body>/ s/<\/body>.*//
                        p
                    }' "$fIn"
     fi
done

print - "</body>"
print - "</html>"

exit 0

I hope this helps.

bakunin