title: How to find a match to a partial string and then delete the string from the reference file using awk?
body: <p>I have a problem that I have been trying to solve, but have not been able to figure out how to do it.  I have a reference file that has all of the devices in my inventory by bar code.</p>
  <p>Reference file:</p>
  <pre><code>PTR10001,PRINTER,SN A
  PTR10002,PRINTER,SN B
  PTR10003,PRINTER,SN C 
  MON10001,MONITOR,SN A
  MON10002,MONITOR,SN B
  MON10003,MONITOR,SN C
  CPU10001,COMPUTER,SN A
  CPU10002,COMPUTER,SN B
  CPU10003,COMPUTER,SN C
  </code></pre>
  <p>What I would like to do is make a file where I only have to put the abbreviation of what I need on it.
  File 2 would look like this:</p>
  <pre><code>PTR
  CPU
  MON
  MON
  </code></pre>
  <p>The desired output of this would be a file that would tell me what items by barcode that I need to pull off the shelf.<br />
  Desired output file:</p>
  <pre><code>PTR10001
  CPU10001
  MON10001
  MON10002
  </code></pre>
  <p>As seen in the output, since I cannot have 2 of the same barcode, I need it to look through the reference file and find the first match.  After the number is copied to the output file, I would like to remove the number from the reference file so that it doesn't repeat the number.</p>
  <p>I have tried several iterations of awk, but have not been able get the desired output.<br />
  The closest that I have gotten is the following code:</p>
  <pre><code>awk -F'/' '{ key = substr($1,1,3) } NR==FNR {id[key]=$1; next} key in id { $1=id[key] } { print }' $file1 $file2 &gt; $file3
  </code></pre>
  <p>I am writing this in ksh, and would like use awk as I think this would be the best answer to the problem.
  Thanks for helping me with this.</p>