Creating numbers of large HTML files by scripting

5 respostas [Última entrada]
Joined: 01/04/2015

With Magic Banana's help in scripting HTML file creation has been a big
help in giving me the confidence to take on some big jobs.

My action plan is to prepare a Head section containing an explanation of
what's going on, plus links to the body sections, followed by a Tail section
taking care of housekeeping at the bottom of each page.

I've used the paste -s command to put all three together:
paste -s Head Body Tail > HTMLPage

This produces a proper webpage, wherein a Body section is attached below an
unchanging Head section one-at-a-time, and the Body sections are changed by
activating each link in succession. The problem is that the source code of
a 6,000 row table is collapsed into four rows, making editing impossible.

I'm going to try the cat command instead:
cat Head Body Tail > HTMLPage
Here I can create a multi-line script containing just the file names which
doesn't involve copying the source code multiple times and ought not to
collapse all the nice architecture of the HTML code.

I'll soon post the outcome ...

George Langford

Magic Banana

I am a member!

Joined: 07/24/2010

Please show us an excerpt of the input and the expected output. paste merge lines, whereas cat concatenates files. They are not interchangeable.

Joined: 01/04/2015

The pertinent files are attached:
Three Body files (005-Data.txt, 012-Data.txt and 005-Data.txt)
One Head file (Head-example.txt)
One Tail file (Tail-example.txt)
Three Output files (Output005.txt, Output012.txt and Output013.txt)

The Script files will be just three lines.

I once got away with using paste -s to combine three pieces of an
output file from two constant inputs and a variable input, but I
won't try that again ...

005-Data.txt 741 bytes
012-Data.txt 718 bytes
013-Data.txt 684 bytes
Tail-example.txt 91 bytes
Head-example.txt 1.36 KB
Output013.txt 5.49 KB
Output012.txt 3.81 KB
Output005.txt 3.77 KB
Magic Banana

I am a member!

Joined: 07/24/2010

Those are not *expected* outputs. It looks like you simply need cat. But you already use it do and then execute another command relying on a file, Outputs.txt, that you do not give.

Joined: 01/04/2015

Magic Banana thinks Outputs.txt is missing ...

It's actually just a list of the three output files.

cat Head-example.txt 005-Data.txt Tail-example.txt > Output-005.html
cat Head-example.txt 012-Data.txt Tail-example.txt > Output-012.html
cat Head-example.txt 013-Data.txt Tail-example.txt > Outout-013.html

It's also necessary to place the following HTML code at the end of the
Head-example.txt file to achieve continuity between the Head-example.txt
file and the XXX-Data.txt file:

These work when I build them by hand, copying & pasting the Head-example.txt
filename in front of the listed 005-Data.txt, 012-Data.txt, and 013-Data.txt
filenames, then copying & pasting the Tail-example.txt filename after the
first two in each row, and then using the paste command to place the list of
output files after the [three-row] list of files to be catted. That makes the
final script.

The same outcome can be achieved by constructing the cat command with paste -d.

George Langford

Joined: 01/04/2015

Outcome ==>
cat Head.html Body.html Tail.html > Output.Script.html
paste -d '' Output.Script.html Outputs.txt > Script-Webpages
sudo chmod +x Script-Webpages

In the first step above, there were N copies of the Head.html file and
Tail.html file, and N different Body.html files and Outputs.txt files.

It actually took several trial runs to get the links in the original table
in the head source code to match the file names in the output webpages, and
to graft the table(s) in the head section to the variable-content tables in
the outputs, especially to get the cell boundaries and background color of
the data tables to be displayed on the webpage(s). The edits took little time
because an edit to one part could be replicated N times by the script. There
was no compression of the source codes in the webpages.

George Langford