Merge Html Files

For a simulation that we are running we get a lot of html files as output. Could anyone suggest a method by which i could merge those multiple html files into a single html file.

Answers (3)

Jason Ross
Jason Ross on 18 May 2011
Since HTML is simply a text file you can append these together very easily. Both UNIX and Windows support these types of operations. If you have a lot of files you will need to script it, but that's a pretty straightforward operation in pretty much any scripting language.
UNIX:
touch mylargehtml.html
cat file1.html >> mylargehtml.html
cat file2.html >> mylargehtml.html
Windows:
type file1.html > mylargehtml.html
type file2.html >> mylargehtml.html
Depending on other requirements (order of input files, making correct html, or if you are actually performing a merge operation), this may need to be more sophisticated, but this is about as simple as I can think of.

4 Comments

Abhijeet
Abhijeet on 18 May 2011
I should have elaborated. I need to do this using a matlab script.
Jason Ross
Jason Ross on 18 May 2011
Can you elaborate also on what you mean by "merging"? Do you actually care about the contents of the file, or are you just concatenating them together?
Said another way, if you did the above using a system() call, would you obtain the desired result? Or do you need to actually read and manipulate the html before you make the large file?
Jason Ross
Jason Ross on 18 May 2011
Also, are there other requirements or constraints that you didn't elaborate (files are scattered all over the place and you need to find them, the order is critical, you need to only take certain files, etc).
Sean de Wolski
Sean de Wolski on 18 May 2011
And of course you can call unix from MATLAB.
doc unix

Sign in to comment.

Walter Roberson
Walter Roberson on 18 May 2011

0 votes

Do each of the HTML files have their own HEAD and BODY sections? Are there META directives in the HEAD sections that might conflict with each other, or style information that might conflict? When the files are all merged together, should it be "body of the first followed immediately by body of the second" or should there be some kind of delimiter between the parts? Would it perhaps make sense that instead of merging the files, that you generate an index file that refers to all of the pieces? If the parts must be merged in to the same file, does an index need to be placed on top so that the parts can be jumped to directly?
Some of these variations are very easy to program; others take more work.
Abhijeet
Abhijeet on 5 Jun 2011

0 votes

I found a good way to do what I wanted. Thanks to Sven Korner for the solution.
To read html file in string it is better to use urlread:
str = urlread('file:///C:/Users/sk/Desktop/3d-PDF/jvtest/peaksurface.html');
str2 = urlread('file:///C:/Users/sk/Desktop/3d-PDF/jvtest/skull.html');
fid = fopen('C:/Users/sk/Desktop/3d-PDF/jvtest/test_abc.html','wb')
fwrite(fid,str_ges)
fclose(fid)

1 Comment

Might as well use fileread() http://www.mathworks.com/help/techdoc/ref/fileread.html
str = fileread('peaksurface.html');
str2 = fileread('skull.html');
fid = fopen('test_abc.html','w');
fwrite(fid,[str str2]);
fclose(fid)

Sign in to comment.

Categories

Tags

Asked:

on 17 May 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!