Convert Text to Html

Convert your text file to html in Linux by Command line.
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=\”left\” width=” length “0 size=1>”; next}

lines consisting of a number of equalising are replaced by a thick <hr>

/^===*$/  {print “<hr align=\”left\” width=” length “0 size=3>”; next}

less than and greater than the sign must be replaced by tags.


Replace form feeds by a couple of empty lines


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