title: How can I use awk to only print values in a given row of file1 if they match with a list in column 1 in file2?
body: <p>I need to remove items after the second column of file1 if they are not in a list of items in file2, which is just 1 column. Space delimiters are used.</p>
  <pre><code>$ cat file1
  ID1 item1 item2 item3 item4 item5 item6 
  ID2 item4
  ID3 item1 item5 item6
  ID4 item2 item3
  
  $ cat file2
  item1
  item3 
  item6
  </code></pre>
  <p>Desired Output:</p>
  <pre><code>ID1 item1 item3 item6
  ID2
  ID3 item1 item6
  ID4 item3
  </code></pre>
  <p>I have tried all day with multiple codes to get this to work. The one that seems the simplest is here:</p>
  <pre><code>awk -F'[ ]' '
  {
      s = $1
      seen[$1]++
      for(i=2; i&lt;=NF; i++)
              if ($1 in seen[$i]) s = s &quot; &quot; $i
      print s
      delete seen
  }
  ' file1 file2 
  </code></pre>
  <p>I just end up with:</p>
  <pre><code>awk: cmd. line:6: (FILENAME=output6.o FNR=1) fatal: attempt to use a scalar value as array
  </code></pre>