title: How to print lines with multiple associative arrays and conditions using awk
body: <p>I want to print all lines from file 1 where the values of $1 and $4 are found in $1 and $4 of file 2 AND where the value in file 1 $2 is greater than or equal to the value in file 2 $2 AND where the value in file 1 $3 is less than or equal to the value in file 2 $3.</p>
  
  <blockquote>
    <p>file 1</p>
  </blockquote>
  
  <pre><code>1   110201809   117658766   a
  1   168095261   182305990   b
  1   215456074   233436403   c
  2   9465687     12905490    d
  2   28765309    35235120    e
  2   48958595    64702082    f
  </code></pre>
  
  <blockquote>
    <p>file 2</p>
  </blockquote>
  
  <pre><code> 1  245371026   249210707   a
   2  937388      46504962    h
   2  937388      162731186   b
   2  2954974     6777829     c
   2  9465687     12996275    d
   2  14539477    44757554    d
   2  14766820    30080818    m
   2  16531332    23584565    n
   2  17340076    26206255    o
   2  18535880    24452180    p
   2  28830071    35289330    q
   2  36206662    47273732    r
   2  48958495    64703082    f
  </code></pre>
  
  <p>Desired output only prints the lines from file 1 that meet the condition.</p>
  
  <blockquote>
    <p>desired output</p>
  </blockquote>
  
  <pre><code> 2  9465687     12905490    d
   2  48958595    64702082    f
  </code></pre>
  
  <p>I've tried the following which gave an empty file:</p>
  
  <pre><code>awk 'NR==FNR{ a[$1,$4]= $0; b[$2] = $2 ; c[$3] = $3; next }  ($1 $4 in a) &amp;&amp; ($2 &gt;= b[$2]) &amp;&amp; ($3 &lt;= c[$3])' file2 file1&gt;desired output
  </code></pre>