how to convert txt file to HTML using shell?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • quartz
    New Member
    • Aug 2007
    • 19

    how to convert txt file to HTML using shell?

    Hello,

    May I convert txt file to HTML using shell?

    Thenks,
  • WinblowsME
    New Member
    • Jan 2008
    • 58

    #2
    Code:
    #! /bin/bash
    
    echo "<html>" > test.html
    cat test.txt >> test.html
    echo "</html>" >> test.html

    Comment

    • quartz
      New Member
      • Aug 2007
      • 19

      #3
      I tried but not get what I wont. I have txt file:
      name city phone
      David Wiena 33333
      Sofi Paris 88888
      etc

      I wont to convert it to html file with no any changed?

      When I tried what u told me I get:
      name, city phone, david .... as hml file.

      Thenks

      Comment

      • WinblowsME
        New Member
        • Jan 2008
        • 58

        #4
        Code:
        #! /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
        
           while read line ; do
              echo "$line<br>" >> $html
           done < $file
        
           echo "   </body>" >> $html
           echo "</html>" >> $html
        done

        Comment

        Working...