title: how to compare numeric fields in two files with awk
body: <p>i have these two files :
  file1 </p>
  
  <pre><code>2537
  
  1279
  
  1075
  
  12799
  
  1474
  
  135441
  
  1260
  
  1169
  
  1281
  
  10759
  </code></pre>
  
  <p>and 
  file2 </p>
  
  <pre><code>1070,1279960511,BR,USA,UNITED STATES
  1278,1279960511,US,USA,UNITED STATES
  1279,1279960527,CA,CAN,CANADA
  1289,1279967231,US,USA,UNITED STATES
  2679,1279971327,CA,CAN,CANADA
  1279,1279971839,US,USA,UNITED STATES
  1279,1279972095,CA,CAN,CANADA
  1279,1279977471,US,USA,UNITED STATES
  127997,1279977983,CA,CAN,CANADA
  127997,1279980159,US,USA,UNITED STATES
  127998,1279980543,CA,CAN,CANADA
  107599,1075995007,US,USA,UNITED STATES
  107599,1075995023,VG,VGB,VIRGIN ISLANDS, BRITISH
  107599,1075996991,US,USA,UNITED STATES
  107599,1075997071,CA,CAN,CANADA
  </code></pre>
  
  <p>i want to : for each entry of file1 go through first column of file2 and when the value in this column become bigger than out "file1" element then return the 3rd element of file2
  i have tried many manyy ways but none worked i either get an empty file or it print something diff than i expect 
  my last try is :</p>
  
  <pre><code>awk -F, '
  BEGIN {FS="," ; i=1 ; while (getline &lt; "file2") { x[i] = $1 ; y[i] = $3 ; i++ }}
  
  { a[$1] = $1 ; h=1 ; while (x[h] &lt;= a[$1]) { h++ } ; { print y[h] }}' file1
  </code></pre>
  
  <p>but this runs forever it doesnt stop neither gives anything
  help me plzzz this has been killing me for days now and i am giving up 
  thanks </p>
  
  <p>Desired output :</p>
  
  <pre><code>#this is a comment and i ll write file 2 as if it was a matrix  
  
  because file1[1] &gt; file2[1,1] ... and file1[1] &gt; file2[2,1] .... and file1[1] &gt; file2[3,1] ... and file1[1] &gt; file2[4,1] but file1[1] &lt; file2[5,1] ... then print file2[4,3] ... which is "US"
  
  now go to file1[2] :
  
  file[2] &gt; file2[1,1] ... and file1[2] &gt; file2[2,1] ... but file1[2] &lt;= file2[3,1] ... then print file2[3,3] 
  </code></pre>
  
  <p>in summary i want to print : "the third elemenent (col) of the first line (from file2) the file1 element first becomes > the first element of next line (file2)</p>