title: Iterating through grep results line by line not delimited by space
body: <p>I'm using a bash script to identify where something is used and then find a corresponding reference (name).</p>
  
  <p>The script is:</p>
  
  <pre><code>#!/bin/bash
  
  echo "running, searching for instances of ${1:0:1}/$1"
  
  for i in ls -d Module*; do
      if [ -d "$i" ]; then
          if [ -f $i/003.Design/003.Data.efx ]; then
              if grep -qe "Module-0000/003.Design/005.Types/${1:0:1}/$1" $i/003.Design/003.Data.efx; then
                  echo $i $i/003.Design/003.Data.efx
                  grep -B 4 "Module-0000/003.Design/005.Types/${1:0:1}/$1" $i/003.Design/003.Data.efx | grep "name"
              fi
          fi
      fi
  done
  </code></pre>
  
  <p>I'm trying to change it to:</p>
  
  <pre><code>#!/bin/bash
  
  echo "running, searching for instances of ${1:0:1}/$1"
  for i in ls -d Module*; do
      if [ -d "$i" ]; then
          if [ -f $i/003.Design/003.Data.efx ]; then
              if grep -qe "Module-0000/003.Design/005.Types/${1:0:1}/$1" $i/003.Design/003.Data.efx; then
                  echo $i $i/003.Design/003.Data.efx
                  for j in `grep -B 4 "Module-0000/003.Design/005.Types/${1:0:1}/$1" $i/003.Design/003.Data.efx | grep "name"` ; do
                      echo $j
                  done
              fi
          fi
      fi
  done
  </code></pre>
  
  <p>When I make the above change to iterate through the results, the results are all screwed up. I suspect that my use of <code>for</code> is incorrect.</p>
  
  <p>I should note that the results before the change are:</p>
  
  <pre><code>$ ./findEllipseType.sh AveragePrice
  running, searching for instances of A/AveragePrice
  Module-3110 Module-3110/003.Design/003.Data.efx
        &lt;ownedAttribute xmi:id="_P7sUcAg7EdysLcyAWbYneA" name="EstPrice"&gt;
  Module-3140 Module-3140/003.Design/003.Data.efx
        &lt;ownedAttribute xmi:id="_Z2v4IaW-EduyI4lEFgFo8g" name="StoresSalePrice"&gt;
        &lt;ownedAttribute xmi:id="_bpCVJaW-EduyI4lEFgFo8g" name="StoresSalePrice"&gt;
        &lt;ownedAttribute xmi:id="_j0crsMnVEeOm9cfLF6jryw" name="EstPrice"&gt;
  Module-3210 Module-3210/003.Design/003.Data.efx
        &lt;ownedAttribute xmi:id="_dYMlpaW-EduyI4lEFgFo8g" name="GrossPriceP"&gt;
        &lt;ownedAttribute xmi:id="_duQVQqW-EduyI4lEFgFo8g" name="GrossPriceP"&gt;
        &lt;ownedAttribute xmi:id="_dujQI6W-EduyI4lEFgFo8g" name="CurrNetPrP"&gt;
        &lt;ownedAttribute xmi:id="_eNZISqW-EduyI4lEFgFo8g" name="GrossPriceP"&gt;
        &lt;ownedAttribute xmi:id="_eNi5QKW-EduyI4lEFgFo8g" name="PrevGpP"&gt;
        &lt;ownedAttribute xmi:id="_eNsqQqW-EduyI4lEFgFo8g" name="CurrNetPrP"&gt;
        &lt;ownedAttribute xmi:id="_eNsqSqW-EduyI4lEFgFo8g" name="PrevNetPrP"&gt;
        &lt;ownedAttribute xmi:id="_fRV4kqW-EduyI4lEFgFo8g" name="CurrNetPrP"&gt;
        &lt;ownedAttribute xmi:id="_fRV4mqW-EduyI4lEFgFo8g" name="GrossPriceP"&gt;
        &lt;ownedAttribute xmi:id="_fgsjMqW-EduyI4lEFgFo8g" name="EstPrice"&gt;
        &lt;ownedAttribute xmi:id="_fg1tJaW-EduyI4lEFgFo8g" name="ActGrossPr"&gt;
  Module-3560 Module-3560/003.Design/003.Data.efx
        &lt;ownedAttribute xmi:id="_xM44IKW-EduyI4lEFgFo8g" name="UnitPrice"&gt;
        &lt;ownedAttribute xmi:id="_xOYF8KW-EduyI4lEFgFo8g" name="UnitPrice"&gt;
        &lt;ownedAttribute xmi:id="_xdbOkKW-EduyI4lEFgFo8g" name="AmendPrice"&gt;
  </code></pre>
  
  <p>But when I've made the change it appears as (truncated):</p>
  
  <pre><code>$ ./findEllipseType.sh AveragePrice
  running, searching for instances of A/AveragePrice
  Module-3110 Module-3110/003.Design/003.Data.efx
  &lt;ownedAttribute
  xmi:id="_P7sUcAg7EdysLcyAWbYneA"
  name="EstPrice"&gt;
  Module-3140 Module-3140/003.Design/003.Data.efx
  &lt;ownedAttribute
  xmi:id="_Z2v4IaW-EduyI4lEFgFo8g"
  name="StoresSalePrice"&gt;
  &lt;ownedAttribute
  xmi:id="_bpCVJaW-EduyI4lEFgFo8g"
  name="StoresSalePrice"&gt;
  &lt;ownedAttribute
  xmi:id="_j0crsMnVEeOm9cfLF6jryw"
  name="EstPrice"&gt;
  Module-3210 Module-3210/003.Design/003.Data.efx
  &lt;ownedAttribute
  xmi:id="_dYMlpaW-EduyI4lEFgFo8g"
  </code></pre>
  
  <p>Looking through the results it appears as though the <code>for in</code> is using a space delimiter when I want it to use a line delimiter. How do I change this please?</p>