LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Blogs > peonuser
User Name
Password

Notices


Rate this Entry

File listing to html

Posted 11-01-2014 at 01:55 PM by peonuser
Updated 11-20-2014 at 09:55 AM by peonuser

Downlloaded some pdf files, but wanted to access them from the local server. Did not want to edit several hundred lines into an html file so I create a batch file. Then the job was done in seconds rather than hours. Learned a bit more about sed in the process.

# 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

Yields:

<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>




To get a page, use: links2 -dump file://index.html > page


PDF list

----------------------------------------------------------------------

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
Posted in Uncategorized
Views 994 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 04:38 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration