File listing into an html file.


Just downloaded a bunch of PDF files and I wanted to put them on the server so they could be accessed easily. Since the pdf file list was over 200 items, did not want to go edit every line in the file manually from

Your-personal-intranet-Part-2.pdf

to

<a href="Your-personal-intranet-Part-2.pdf">Your-personal-intranet-Part-2</a><br />

What to do? First was to make a list of the files.

$ ls *.pdf > pdflist

The you get:

...
...
Yagi-foil-HDTV-antenna.pdf
Yet-another-amplified-acoustical-guitar.pdf
Yet-another-cheese-making-episode.pdf
Yet-another-continuity-tester.pdf
Yet-another-dtv-antenna.pdf
Yet-another-simple-portable-disposable-barbecue-.pdf
Yet-another-usb-coolerwarmer.pdf
Yet-another-usb-lamp.pdf
Your-first-Android-Application.pdf
Your-personal-intranet-Part-1.pdf
Your-personal-intranet-Part-2.pdf

First was to make a list of the files.

But then you may not want the pdf extension as part of the descriptions. So now to create a file called descripts without the extensions:

$ cut -d "." -f1 pdflist > descripts

Which creates:

Yagi-foil-HDTV-antenna

Yet-another-amplified-acoustical-guitar

Yet-another-cheese-making-episode

Yet-another-continuity-tester

Yet-another-dtv-antenna

Yet-another-simple-portable-disposable-barbecue-

Yet-another-usb-coolerwarmer

Yet-another-usb-lamp

Your-first-Android-Application

Your-personal-intranet-Part-1

Your-personal-intranet-Part-2

Now we need to start building the file parts with the first part of the href. We are assuming the pdf files will be in the same directory as the html file.

$ sed -i -e 's/^/<a href=\"/' pdflist

<a href="Yagi-foil-HDTV-antenna.pdf

<a href="Yet-another-amplified-acoustical-guitar.pdf

<a href="Yet-another-cheese-making-episode.pdf

<a href="Yet-another-continuity-tester.pdf

<a href="Yet-another-dtv-antenna.pdf

<a href="Yet-another-simple-portable-disposable-barbecue-.pdf

<a href="Yet-another-usb-coolerwarmer.pdf

<a href="Yet-another-usb-lamp.pdf

<a href="Your-first-Android-Application.pdf

<a href="Your-personal-intranet-Part-1.pdf

<a href="Your-personal-intranet-Part-2.pdf

Now we need to close the href

$ sed -i 's/$/\"\>/' pdflist

<a href="Yagi-foil-HDTV-antenna.pdf">

<a href="Yet-another-amplified-acoustical-guitar.pdf">

<a href="Yet-another-cheese-making-episode.pdf">

<a href="Yet-another-continuity-tester.pdf">

<a href="Yet-another-dtv-antenna.pdf">

<a href="Yet-another-simple-portable-disposable-barbecue-.pdf">

<a href="Yet-another-usb-coolerwarmer.pdf">

<a href="Yet-another-usb-lamp.pdf">

<a href="Your-first-Android-Application.pdf">

<a href="Your-personal-intranet-Part-1.pdf">

<a href="Your-personal-intranet-Part-2.pdf">

Lets add the description and create the html file:

$ paste -d "" pdflist descripts > pdflist.html

<a href="Yagi-foil-HDTV-antenna.pdf">Yagi-foil-HDTV-antenna

<a href="Yet-another-amplified-acoustical-guitar.pdf">Yet-another-amplified-acoustical-guitar

<a href="Yet-another-cheese-making-episode.pdf">Yet-another-cheese-making-episode

<a href="Yet-another-continuity-tester.pdf">Yet-another-continuity-tester

<a href="Yet-another-dtv-antenna.pdf">Yet-another-dtv-antenna

<a href="Yet-another-simple-portable-disposable-barbecue-.pdf">Yet-another-simple-portable-disposable-barbecue-

<a href="Yet-another-usb-coolerwarmer.pdf">Yet-another-usb-coolerwarmer

<a href="Yet-another-usb-lamp.pdf">Yet-another-usb-lamp

<a href="Your-first-Android-Application.pdf">Your-first-Android-Application

<a href="Your-personal-intranet-Part-1.pdf">Your-personal-intranet-Part-1

<a href="Your-personal-intranet-Part-2.pdf">Your-personal-intranet-Part-2

And then finally to close up the reference:

$ sed -i 's/$/\<\/a\>\<br \/\>/' pdflist.html

<a href="Yagi-foil-HDTV-antenna.pdf">Yagi-foil-HDTV-antenna</a><br />

<a href="Yet-another-amplified-acoustical-guitar.pdf">Yet-another-amplified-acoustical-guitar</a><br />

<a href="Yet-another-cheese-making-episode.pdf">Yet-another-cheese-making-episode</a><br />

<a href="Yet-another-continuity-tester.pdf">Yet-another-continuity-tester</a><br />

<a href="Yet-another-dtv-antenna.pdf">Yet-another-dtv-antenna</a><br />

<a href="Yet-another-simple-portable-disposable-barbecue-.pdf">Yet-another-simple-portable-disposable-barbecue-</a><br />

<a href="Yet-another-usb-coolerwarmer.pdf">Yet-another-usb-coolerwarmer</a><br />

<a href="Yet-another-usb-lamp.pdf">Yet-another-usb-lamp</a><br />

<a href="Your-first-Android-Application.pdf">Your-first-Android-Application</a><br />

<a href="Your-personal-intranet-Part-1.pdf">Your-personal-intranet-Part-1</a><br />

<a href="Your-personal-intranet-Part-2.pdf">Your-personal-intranet-Part-2</a><br />

Cool. Add a bit of window dressing and we are done.

<html>

<body>

<h2><center>PDF list</center></h2>

<hr>

<a href="Yagi-foil-HDTV-antenna.pdf">Yagi-foil-HDTV-antenna</a><br />

<a href="Yet-another-amplified-acoustical-guitar.pdf">Yet-another-amplified-acoustical-guitar</a><br />

<a href="Yet-another-cheese-making-episode.pdf">Yet-another-cheese-making-episode</a><br />

<a href="Yet-another-continuity-tester.pdf">Yet-another-continuity-tester</a><br />

<a href="Yet-another-dtv-antenna.pdf">Yet-another-dtv-antenna</a><br />

<a href="Yet-another-simple-portable-disposable-barbecue-.pdf">Yet-another-simple-portable-disposable-barbecue-</a><br />

<a href="Yet-another-usb-coolerwarmer.pdf">Yet-another-usb-coolerwarmer</a><br />

<a href="Yet-another-usb-lamp.pdf">Yet-another-usb-lamp</a><br />

<a href="Your-first-Android-Application.pdf">Your-first-Android-Application</a><br />

<a href="Your-personal-intranet-Part-1.pdf">Your-personal-intranet-Part-1</a><br />

<a href="Your-personal-intranet-Part-2.pdf">Your-personal-intranet-Part-2</a><br />

</body>

</html>

Of course the page looks like:


Of course this is all over simplified and more window dressing plus shortcuts could have been taken. Anyway so I came up with a shell file to do the job. that only took a few seconds at most to run. It would have taken a much longer time to edit the file by hand.

# turn a pdf list into a usable http file for a web server.

ls *.pdf > pdflist
cut -d "." -f1 pdflist > descripts
sed -i -e 's/^/<a href=\"/' pdflist
sed -i 's/$/\"\>/' pdflist
paste -d "" pdflist descripts > pdflist.html
sed -i 's/$/\<\/a\>\<br \/\>/' pdflist.html
echo "<html>" > index.html
echo "<body>" >> index.html
echo "<h2><center>PDF list</center></h2>" >> index.html
echo "<hr>" >> index.html
cat pdflist.html >> index.html
echo "</body>" >> index.html
echo "</html>" >> index.html

Now to copy all the files to a directory on the web server!

Update: you can also tags

<pre>
<a href="#a">A</a>
 
<p><a name="a">A</a></p>
</pre>
 
 

Comments

Popular posts from this blog

Guiless?

Web.com and Network Solutions, the Walmart of the internet.

MSOffice vs Libreoffice