title: How to search the numerical range where a given numerical digit lies in between?
body: <p>I have two files</p>
  
  <h3>file1</h3>
  
  <p>SNP data consisting of a chromosome and its position (approximately 400,000 entries)</p>
  
  <pre><code>chr pos
  a1 456
  a2 789
   . .
   . . 
  so on
  </code></pre>
  
  <h3>file2</h3>
  
  <p>GTF data consisting of chromosome, position_start, position_end, and details (approximately 500,000 entries)</p>
  
  <pre><code>chr pos_start pos_end detail
  a1 100 400 gene1
  a1 401 700 gene2
  a2 200 500 gene3
  a2 501 900 gene4
   . .
   . . 
  so on
  </code></pre>
  
  <h3>Desired result</h3>
  
  <pre><code>chr pos chr pos_start pos_end detail
  a1 456 a1 401 700 gene2
  a2 789 a2 501 900 gene4
  </code></pre>
  
  <p>I am getting this result using shell script: </p>
  
  <pre><code>(grep "$chr" file2.gtf | awk '{if($2 &lt;= '$pos' &amp;&amp; $3 &gt;= '$pos') print $0}') 
  </code></pre>
  
  <p>in a while loop, but it takes too much time to process all digits in <code>file1</code>. </p>
  
  <p>Does anyone know a more efficient way in shell, Python, or Perl to accomplish this?</p>