title: how to read one line to calculate the md5
body: <p>I am using Linux bash version 4.1.2</p>
  
  <p>I have a tab-delimited input_file having 5 fields and I want to calculate the MD5 for each line and put the md5sum at the end of each line.</p>
  
  <p>The expected output_file should therefore has 6 fields for each line.</p>
  
  <p>Here is my coding:</p>
  
  <pre><code>cat input_file | while read ONELINE
  do
    THEMD5=`echo "$ONELINE" | md5sum | awk '{print $1}'`
    echo -e "${ONELINE}\t${THEMD5}"
  done &gt; output_file
  </code></pre>
  
  <p>The coding works well most of the time.</p>
  
  <p>However, if ONELINE is ended with single/double tabs, the trailing tab(s) will disappear!</p>
  
  <p>As a result, the output_file will sometimes contain lines of 4 or 5 fields, due to the missing tab(s).</p>
  
  <p>I have tried to add <code>IFS=</code> or <code>IFS=''</code> or <code>IFS=$'\n'</code> or <code>IFS-$'\012'</code> in the <code>while</code> statement, but still cannot solve the problem.</p>
  
  <p>Please help.</p>
  
  <p>Alvin SIU</p>