title: AWK: select rows from shell variables
body: <p>Here I have two files data.txt and mrk.txt.</p>
  
  <p>in 1st line I want to select id that marked with 2 in the 2nd column. and 2nd line I want to just keep rows starting with those ids (3,5,8,9,10) and delete the rest. Does anyone knows how can I make it?</p>
  
  <pre><code>dam=$(awk '$2==2 {print $1}' data.txt)
  ./QmSim2uga.awk -v genotyped="$dam" mrk.txt &gt; c_mark_001
  </code></pre>
  
  <p>QMSim2uga.awk is</p>
  
  <pre><code>#!/bin/gawk -f
  BEGIN{
  nind=0
  FIELDWIDTHS = "3 1 1 1 1 1"
  }
  ($1 == dam){        
      nsnp=NF-1
      genotype=""
      for (i=1; i&lt;=nsnp; i++){
          out=$(i+1)
          # QmSim -&gt; UGA
          # 0 -&gt; AA -&gt; 0
          # 2 -&gt; aa -&gt; 2
          # 3 -&gt; Aa -&gt; 1
          # 4 -&gt; aA -&gt; 1
          # (missing does not exist) -&gt; 5
          if(out&gt;2) {out=1} 
          genotype=genotype out
      }
      if (NR % 10000 ==0){ printf("%s\n",NR) &gt; "/dev/stderr" }
      printf("%10s%1s%" nsnp "s\n",$1," ",genotype)
      nind++
  }
  END{
  printf("%s%10s%10s\n","nsnp, nanim",nsnp,NR) &gt; "/dev/stderr"
  }   
  </code></pre>
  
  <p>data.txt</p>
  
  <blockquote>
  <pre><code>1  1
  2  1
  3  2
  4  1
  5  2
  6  1
  7  1
  8  2
  9  2
  10 2
  </code></pre>
  </blockquote>
  
  <p>mrk.txt</p>
  
  <blockquote>
  <pre><code>1  02340
  2  20433
  3  43220
  4  32344
  5  02233
  6  30423
  7  24430
  8  00223
  9  03342
  10 34402
  </code></pre>
  </blockquote>
  
  <p>the desired ouput will be, "3" and "4" in 2nd column of mrk.txt file should be replaced with 1</p>
  
  <blockquote>
  <pre><code>3  11220
  5  02211
  8  00221
  9  01112
  10 11102
  </code></pre>
  </blockquote>
  
  <p>But right now with the code given, the ouptfile is empty</p>