title: Trying to read a file in bash and grep for a substring, store that substring in an array
body: <p>I have a file named test.txt that has some data as follows:</p>
  
  <pre class="lang-none prettyprint-override"><code>*************************** 19. row ***************************
         created_at: 2018-07-02 19:57:58
         deleted_at: 2018-07-03 14:17:05
         serial_num: 1269043217201
  *************************** 20. row ***************************
         created_at: 2018-07-02 19:57:58
         deleted_at: 2018-07-03 14:17:05
         serial_num: 1269043217202
  </code></pre>
  
  <p>I need to store all the serial numbers in an array. I've tried something basic to print:</p>
  
  <pre class="lang-sh prettyprint-override"><code>filename="test.txt"
  c=0
  while read -r line
      do
         echo $line | grep serial_num | sed -n -e 's/serial_num: //p'
      done &lt; "$filename"
  </code></pre>
  
  <p>This prints data like which looks good:</p>
  
  <pre class="lang-none prettyprint-override"><code>1280521737734
  1280521737735
  1280521737736
  </code></pre>
  
  <p>But when I add </p>
  
  <pre class="lang-sh prettyprint-override"><code>sn=(echo $line | grep serial_num | sed -n -e 's/serial_num: //p')
  echo $sn
  </code></pre>
  
  <p>This starts to print blank lines as well. How do I avoid that? 
  Also doing this </p>
  
  <pre class="lang-sh prettyprint-override"><code>servs[$c] = $sn
  c=$(expr $c + 1)
  </code></pre>
  
  <p>returns</p>
  
  <pre class="lang-none prettyprint-override"><code>./test.sh: line 138: servs[0]: command not found
  ./test.sh: line 138: servs[1]: command not found
  ./test.sh: line 138: servs[2]: command not found
  </code></pre>