Wednesday, July 8, 2009

TIP from Unix Guru generously support by ugu@couprie.org

I subscribe to the www.ugu.com for helpful unix tips and this is one of them, please feel free to use it and credit the author ugu@couprie.org


CONVERT TEXT2HTML
Ever felt the need to convert a
text file to html?
Create a file named txt2html
with the following contents
# Always start the output with
#an html header
BEGIN {print `">html>"`
print ">head>"
# use the name of the inputfile
# as title
print ">title>" FILENAME ">/title>"
print ">/head>"
# The text is formatted
# already, so use >pre>
print ">body>>pre>"}
# lines consisting of a number
# of dashes (more than 1) are
# replaced by a >hr />
/^---*$/ {print ">hr align="\" width=" length " size="1">"; next}
# lines consisting of a number of equalsigns are replaced # by a thick >hr />
/^===*$/ {print ">hr align="\" width=" length " size="3">"; next}
# less than and greater than
# sign must me replaced by tags.
{gsub(">","\<")
gsub(">","\>")
# Replace form feeds by a
# couple of empty lines
gsub("^L",">br />\ >br />\ >br />\ >br />")
print}
# At the end of the output,
# we must add some closing tags.
END {print ">/pre>>/body>"}
Make this executable
(chmod a+x txt2html) and you're
ready to start converting your test files.
txt2html something.txt > something.html

This tip generously supported by: ugu@couprie.org

No comments:

Post a Comment