title: select lines based on multiple criteria from a second file using awk or similar
body: <p>I have two files, and want to label lines of one file (Data file) based on multiple criteria satisfied by the second file (Condition file).</p>
  
  <p>Data file:</p>
  
  <pre>
  Scaffold    Nucleotide_position x   SNP1    SNP2
  001 345 .   G   T
  001 568 .   G   C
  001 1945    .   T   C
  001 5001    .   T   A
  001 5600    .   T   G
  001 6001    .   A   T
  001 10889   .   G   A
  001 12001   .   T   A
  001 15001   .   G   A
  002 45  .   C   T
  002 104 .   G   T
  002 598 .   C   A
  002 4800    .   T   A
  002 5001    .   G   C
  002 7200    .   T   A
  002 9845    .   A   G
  002 11001   .   T   C
  002 13450   .   G   A
  003 123 .   C   T
  003 125 .   A   G
  003 155 .   A   C
  003 500 .   T   C
  003 983 .   C   G
  003 1001    .   G   T
  004 2   .   A   G
  004 567 .   T   C
  004 901 .   C   A
  004 5672    .   T   G
  004 9001    .   C   G
  004 10098   .   A   T</pre>
  
  <p>Condition file:</p>
  
  <pre>Scaffold   Locus_type  Min Max
  001 exon    4456    5543
  001 exon    5678    6668
  001 exon    8955    9939
  001 exon    10778   13444
  002 exon    4785    4800
  002 exon    5200    8000
  002 exon    10000   12000
  003 exon    124 154
  003 exon    854 1025
  004 exon    21  852
  004 exon    8951    9512</pre>
  
  <p>Desired output:</p>
  
  <pre>
  001 345 .   G   T
  001 568 .   G   C
  001 1945    .   T   C
  001 5001    .   T   A   *SNP IN EXON
  001 5600    .   T   G
  001 6001    .   A   T   *SNP IN EXON
  001 10889   .   G   A   *SNP IN EXON
  001 12001   .   T   A   *SNP IN EXON
  001 15001   .   G   A
  002 45  .   C   T
  002 104 .   G   T
  002 598 .   C   A
  002 4800    .   T   A   *SNP IN EXON
  002 5001    .   G   C
  002 7200    .   T   A   *SNP IN EXON
  002 9845    .   A   G
  002 11001   .   T   C   *SNP IN EXON
  002 13450   .   G   A
  003 123 .   C   T
  003 125 .   A   G   *SNP IN EXON
  003 155 .   A   C
  003 500 .   T   C
  003 983 .   C   G   *SNP IN EXON
  003 1001    .   G   T   *SNP IN EXON
  004 2   .   A   G
  004 567 .   T   C
  004 901 .   C   A
  004 5672    .   T   G
  004 9001    .   C   G   *SNP IN EXON
  004 10098   .   A   T </pre>
  
  <p>Failed command using awk:</p>
  
  <pre>
  awk 'NR==FNR{a[$1]=$3 FS=="\t" $4;next}{if (a[$1]==$1 && $3&lt=$2 && $4>=$2) print $0, "*SNP IN EXON"; else print $0, "";}' Condition_file.txt Data_file.txt </pre>
  
  <p>Basically, I want to label only those lines in the data file that include a nucleotide (SNP) that falls within the range (min and max) of each of the identified exons listed in the second file (or Condition file).  I have multiple SNPs and exons per scaffold, which is what I think is causing problems with the awk command.</p>
  
  <p>NOTE: my real datafile has thousands of scaffolds, SNPs, and exons</p>
  
  <p>This seems like a very basic problem, but I am at a loss given my limited experience. Help is greatly appreciated.</p>