title: Creating .html file from logfile
body: <p>I need a script which converts log files into easily viewable .html files, accessible by "anyone".</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>#!/bin/bash
  
  ## The purpose of this script is to create .html files from log files, with the ability to optionally GREP for certain strings
  
  if [ "$2" == "" ];
  then
          echo "Usage : $0 [Source Log file] [Output HTML file] [String to grep (if applicable)]"
          exit 255
  fi;
  
  LOGFILE=$1
  OUTPUTFILE=$2
  GREPSTRING=$3
  
  if [ "$3" == "" ];
  then
          echo "Cat'ing $LOGFILE to $OUTPUTFILE"
          LOGCONTENTS=`cat $LOGFILE`
  
  else
          echo "Grep'ing for $GREPSTRING in $LOGFILE"
          LOGCONTENTS=`grep --color $GREPSTRING $LOGFILE | sed -e "s/^.*$/&amp;1\n/"`
  fi;
  
  # Below is the html heading which will be appended to the final .html file
  HEADING="&lt;html&gt;&lt;body&gt;&lt;h1&gt;Log output for: $LOGFILE&lt;/h1&gt;"
  
  # Below is the end of the html file
  END="&lt;/body&gt;&lt;/html&gt;"
  
  # Below all the prepared variables are stitched together to the OUTPUT/LOG FILE
  echo $HEADING &gt; $OUTPUTFILE
  echo $LOGCONTENTS &gt;&gt; $OUTPUTFILE
  echo $END &gt;&gt; $OUTPUTFILE
  
  
  # For debugging, enable the lines below
  echo $LOGCONTENTS
  echo "Done preparing $OUTPUTFILE"
  </code></pre>
  
  <p>My problem is that the output, no matter how much I play with CAT, GREP, SED etc, does not preserve line breaks. It is essential for the output file to look more or less like when doing a normal tail -f or cat.</p>