title: Bash Script: Grabbing First Item Per Line, Throwing Into Array
body: <p>I'm fairly new to the world of writing Bash scripts and am needing some guidance. I've begun writing a script for work, and so far so good. However, I'm now at a part that needs to collect database names. The names are actually stored in a file, and I can grep them.</p>
  
  <p>The command I was given is <code>cat /etc/oratab</code> which produces something like this:</p>
  
  <pre><code># This file is used by ORACLE utilities.  It is created by root.sh
  # and updated by the Database Configuration Assistant when creating
  # a database.
  
  # A colon, ':', is used as the field terminator.  A new line terminates
  # the entry.  Lines beginning with a pound sign, '#', are comments.
  #
  # The first and second fields are the system identifier and home
  # directory of the database respectively.  The third filed indicates
  # to the dbstart utility that the database should , "Y", or should not,
  # "N", be brought up at system boot time.
  #
  OEM:/software/oracle/agent/agent12c/core/12.1.0.3.0:N
  *:/software/oracle/agent/agent11g:N
  dev068:/software/oracle/ora-10.02.00.04.11:Y
  
  dev299:/software/oracle/ora-10.02.00.04.11:Y
  
  xtst036:/software/oracle/ora-10.02.00.04.11:Y
  
  xtst161:/software/oracle/ora-10.02.00.04.11:Y
  dev360:/software/oracle/ora-11.02.00.04.02:Y
  dev361:/software/oracle/ora-11.02.00.04.02:Y
  xtst215:/software/oracle/ora-11.02.00.04.02:Y
  xtst216:/software/oracle/ora-11.02.00.04.02:Y
  dev298:/software/oracle/ora-11.02.00.04.03:Y
  xtst160:/software/oracle/ora-11.02.00.04.03:Y
  </code></pre>
  
  <p>I turn turned around and wrote <code>grep ":/software/oracle/ora" /etc/oratab</code> so it can grab everything I need, which is 10 databases. Not the most elegant way, but it gets what I need:</p>
  
  <pre><code>dev068:/software/oracle/ora-10.02.00.04.11:Y
  dev299:/software/oracle/ora-10.02.00.04.11:Y
  xtst036:/software/oracle/ora-10.02.00.04.11:Y
  xtst161:/software/oracle/ora-10.02.00.04.11:Y
  dev360:/software/oracle/ora-11.02.00.04.02:Y
  dev361:/software/oracle/ora-11.02.00.04.02:Y
  xtst215:/software/oracle/ora-11.02.00.04.02:Y
  xtst216:/software/oracle/ora-11.02.00.04.02:Y
  dev298:/software/oracle/ora-11.02.00.04.03:Y
  xtst160:/software/oracle/ora-11.02.00.04.03:Y
  </code></pre>
  
  <p>So, if I want to grab the name, such as dev068 or xtst161, how do I? I think for what I need to do with this project moving forward, is storing them in an array. As mentioned in the documentation, a colon is the field terminator. How could I whip this together so I have an array, something like:</p>
  
  <pre><code>dev068
  dev299
  xtst036
  xtst161
  dev360
  dev361
  xtst215
  xtst216
  dev298
  xtst160
  </code></pre>
  
  <p>I feel like I may be asking for too much assistance here but I'm truly at a loss. I would be happy to clarify if need be.</p>