title: Concatenate grep output string (bash script)
body: <p>I'm processing some data from a text file using a bash script (Ubuntu 12.10). </p>
  
  <p>The basic idea is that I select a certain line from a file using grep. Next, I process the line to get the number with sed. Both the grep and sed command are working. I can echo the number.</p>
  
  <p>But the concatenation of the result with a string goes wrong.</p>
  
  <p>I get different results when combining string when I do a grep command from a variable or a file. The concatenation goes wrong when I grep a file. It works as expected when I grep a variable with the same text as in the file.</p>
  
  <p>What am I doing wrong with the grep from a file?</p>
  
  <p><strong>Contents of test.pdb</strong></p>
  
  <pre><code>REMARK overall = 324.88  
  REMARK bon     = 24.1918  
  REMARK coup    = 0  
  </code></pre>
  
  <p><strong>My script</strong></p>
  
  <pre class="lang-bsh prettyprint-override"><code>#!/bin/bash
  
  #Correct function
  echo "Working code"
  TEXT="REMARK overall = 324.88\nREMARK bon     = 24.1918\nREMARK coup    = 0\n"
  DATA=$(echo -e $TEXT | grep 'overall' | sed -n -e "s/^.*= //p" )
  
  echo "Data: $DATA"
  DATA="$DATA;0"
  echo $DATA
  
  
  #Not working
  echo ""
  echo "Not working code"
  DATA=$(grep 'overall' test.pdb | sed -n -e "s/^.*= //p")
  
  echo "Data: $DATA"
  DATA="$DATA;0"
  echo $DATA
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Working code
  Data: 324.88
  324.88;0
  
  Not working code
  Data: 324.88
  ;04.88
  </code></pre>