title: How to printf a variable length line in fixed length chunks?
body: <p>I need to to analyze (with <code>grep</code>) and print (with some formatting) the content of an 
  app's log.</p>
  
  <p>This log contains text data in variable length lines. What I need is, after some grepping, loop each line of this output and print it with a maximum fixed length of 50 characters. If a line is longer than 50 chars, it should print a newline and then continue with the rest in the following line and so on until the line is completed.</p>
  
  <p>I tried to use <code>printf</code> to do this, but it's not working and I don't know why. It just outputs the lines in same fashion of <code>echo</code>, without any consideration about <code>printf</code> formatting, though the <code>\t</code> character (tab) works.</p>
  
  <pre><code>function printContext
  {
      str="$1"
      log="$2"
      tmp="/tmp/deluge/$$"
  
      rm -f $tmp
  
      echo ""
      echo -e "\tLog entries for $str :"
  
      ln=$(grep -F "$str" "$log" &amp;&gt; "$tmp" ; cat "$tmp" | wc -l)
  
      if [ $ln -gt 0 ];
      then
              while read line
              do
                      printf "\t%50s\n" "$line"
              done &lt; $tmp
      fi
  
  }
  </code></pre>
  
  <p>What's wrong? I Know that I can make a substring routine to accomplish this task, but <code>printf</code> should be handy for stuff like this.</p>