Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two HTML files into master HTML file

Let's say I have the following HTML files:

html1.html

<html>
  <head>
    <link href="blah.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div>this here be a div, y'all</div>
  </body>
</html>

html2.html

<html>
  <head>
    <script src="blah.js"></script>
  </head>
  <body>
    <span>this here be a span, y'all</span>
  </body>
</html>

I want to take these two files and make a master file that would look like this:

<html>
  <head>
    <link href="blah.css" rel="stylesheet" type="text/css" />
    <script src="blah.js"></script>
  </head>
  <body>
    <div>this here be a div, y'all</div>
    <span>this here be a span, y'all</span>
  </body>
</html>

Is this possible using a simple Linux command? I've tried looking at join, but it looks like that joins on a common field, and I'm not necessarily going to have common fields... I just need to basically add the difference, but also have the main structure still intact (I guess this could be referred to as a left-join?). Doesn't look like cat will work either... as that merges by appending one file, then the next, etc.

If there isn't a simple Linux command, my next step is to either write a script that compares both scripts line by line, or create a master HTML file that references these two individual files somehow.

like image 995
incutonez Avatar asked Nov 08 '13 19:11

incutonez


1 Answers

Use pandoc to merge e.g. all html-files in the current directory:

pandoc -s *.html -o output.html
like image 61
Lars Bilke Avatar answered Oct 17 '22 04:10

Lars Bilke