Write an awk (nawk) or sed command file that converts a textfile to a html file (by inserting tags <HTML><BODY><PRE> at the beginning of your existing file: file1.txt and inserting tags </PRE> ></BODY></HTML> at the end of file1.txt)
Sample Run:
awk -f awkfile.txt file1.txt > file1.html
or use
sed –f sedfile.txt file1.txt > file1.html
Sample Output:
Use a browser to show your file1.html
This script file can be used to convert a text file to html file
#! /bin/bash
if [ $# -eq 0 ] ; then
echo "USAGE: $(basename $0) file1 file2 file3 ..."
exit 1
fi
for file in $* ; do
html=$(echo $file | sed 's/\.txt$/\.html/i')
echo "<html>" > $html
echo " <body>" >> $html
echo " <pre>" >> $html
while read line ; do
echo "$line<br>" >> $html
done < $file
echo " </body>" >> $html
echo "</html>" >> $html
echo " </pre>" >> $html
done
This below command will simply convert any html file to text file without using script file sed 's/<[^>]*>//g ; /^$/d' htmlpage.html > output.txt
Get Answers For Free
Most questions answered within 1 hours.