title: Awk item from column one, then awk again using the result in column two?
body: <p>I have a CSV that I need to sort through using a key provided that'd be in the first column of said CSV, and then I need to <code>awk</code> again and search via column 2 and return all matching data.</p>
  
  <p>So: I'd <code>awk</code> with the first key, and it'd return just the result of the second column [so just cell]. Then I'd awk using the cell contents and have it return all matching rows.</p>
  
  <p>I have almost no <code>bash</code>/<code>awk</code> scripting experience so please bear with me. :)</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>KEY1,TRACKINGKEY1,TRACKINGNUMBER1-1,PACKAGENUM1-1
      ,TRACKINGKEY1,TRACKINGNUMBER1-2,PACKAGENUM1-2
      ,TRACKINGKEY1,TRACKINGNUMBER1-3,PACKAGENUM1-3
      ,TRACKINGKEY1,TRACKINGNUMBER1-4,PACKAGENUM1-4
      ,TRACKINGKEY1,TRACKINGNUMBER1-5,PACKAGENUM1-5
  KEY2,TRACKINGKEY2,TRACKINGNUMBER2-1,PACKAGENUM2-1
  KEY3,TRACKINGKEY3,TRACKINGNUMBER3-1,PACKAGENUM3-1
      ,TRACKINGKEY3,TRACKINGNUMBER3-2,PACKAGENUM3-2
  </code></pre>
  
  <p><strong>Command:</strong></p>
  
  <pre><code>awk -v key=KEY1 -F' *,' '$1==key{f=1} $1 &amp;&amp; $1!=key{f=0} f{print $3}' file
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>TRACKINGNUMBER1-1
  TRACKINGNUMBER1-2
  TRACKINGNUMBER1-3
  TRACKINGNUMBER1-4
  TRACKINGNUMBER1-5
  </code></pre>
  
  <p>That's what I've tried. I'd like to <code>awk</code> so if I search for key1 that trackingkey1 is returned, then <code>awk</code> with trackingkey one and output each full matching row.</p>
  
  <hr>
  
  <p>Sorry, I should have been more clear. For example - if I searched for KEY3 I'd <em>like</em> the output to be:</p>
  
  <pre><code>    KEY3,TRACKINGKEY3,TRACKINGNUMBER3-1,PACKAGENUM3-1
          ,TRACKINGKEY3,TRACKINGNUMBER3-2,PACKAGENUM3-2
  </code></pre>
  
  <p>So what I want is I'd search for KEY3 initially, and it would return TRACKINGKEY3. I'd then search for TRACKINGKEY3 and it would return each full row with said TRACKINGKEY3 in it.</p>