title: Data from AWK into an array
body: <p>I've been looking into sorting an input txt file in unix but have run into some issues I'd love some advice on. </p>
  
  <pre><code>Product,color,stock
  apple,red,400
  apple,green,400
  apple,yellow,400
  grape,purple,500
  banana,yellow,120
  </code></pre>
  
  <p>Say this is my input file. It's just a text file but I want to consolidate my information a bit.</p>
  
  <p>I first used awk to group my products together like so...</p>
  
  <pre><code>awk -F '[,]' 'NR &gt;= 1 {b[$1];}
  </code></pre>
  
  <p>This would leave me with the following if I printed it out...</p>
  
  <pre><code>apple
  grape
  banana
  </code></pre>
  
  <p>but if I wanted to include other information such as all the colors of product listed in that row I ran into problems. If I wanted that 'b' index data to go into another array how would I do that (since I can't seem to access 'b' from outside the awk code)? figured the following would work but no luck.</p>
  
  <pre><code>awk -F '[,]' 'NR &gt;= 1 {b[$1];}END{for (i in b) productArray+=(b[i])}'
  </code></pre>