title: bash for loop variable with awk
body: <p>This is my first time posting on stack overflow, after being mostly searching for solutions and reading posts.  I am trying to run a loop using bash so I can do the string search over a bunch of different files with the ext .u.clean  I want to look through these files for the string "H#" or "h#" with the # being 1-28, and outputting to a file with the number that was searched for in the string.  I am doing two separate searches in two fields ($5 and $0) and I wanted to output the total number of unique matches to a file "temp"#.txt.  After this I want to do some math on the two numbers that are input in the file.  So far I have gotten this far:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>for i in {1..28}; do
      awk -v var="$i" -F"\t"  ' $19 ~ "_[hH]"var {print $0}' */*.u.clean | \
          sort | uniq | wc -l &gt; 'temp'$i'.txt' | \
          awk -v var="$i" -F"\t"  ' $19 ~ "_[hH]"var {print $5}' */*.u.clean | \
          sort | uniq | wc -l &gt;&gt; 'chris'$i'.txt'
  done
  </code></pre>
  
  <p>The problem is that the numbers are coming out wrong.  I am getting a total of 28 "temp"#".txt" files, but the inputs are not the correct word count numbers.  I also dont know how to do a mathematical operation one I have the files with the numbers in them.  Can someone help me out or point me to the right direction?  Thanks for any help.</p>
  
  <p>EDIT: </p>
  
  <p>Here is what some of the input might look like:</p>
  
  <blockquote>
    <p>112     E       03      294168  FBLN7_rs335586251.5     G       G<br>
    01/23/2013      2       3       VSD control 130123_CR_CH5_H26       1 
    A.Conservative</p>
    
    <p>17      D       11      294319  FBLN7_rs335586251.5     G       G<br>
    06/26/2012      2       3       VSD control<br>
    120626_CR_CH5_H3        1       A.Conservative</p>
    
    <p>22      B       01      294703  FBLN7_rs335586251.5     G       G<br>
    06/26/2012      2       2       VSD control<br>
    120626_CR_CH5_H4        1       A.Conservative</p>
    
    <p>103     A       07      295033  FBLN7_rs335586251.5     G       G<br>
    01/23/2013      2       1       VSD control<br>
    130123_CR_CH5_H23       1       A.Conservative</p>
    
    <p>44      G       07      295119  Tbx5_rs61931008.5     G       G<br>
    07/11/2012      2       5       ASD control<br>
    120711_CR_CH5_H12       1       A.Conservative</p>
    
    <p>42      H       12      295201  JAG1_rs1232607.5      G       G<br>
    07/11/2012      1       2       ASD control<br>
    120711_CR_CH5_H12       1       A.Conservative</p>
  </blockquote>
  
  <p>I am trying to find a count of how many times in field 19 ( the field with the text Tbx5_rs61931008.5.), each occurence of H'#' occurs with # being from 1-28, output that number to a separate file for each H#.  Then I want to know withing these matches of H#, how many unique occasions of field 5 there are, and output that number to the same file for each H#.  I hope this is clear, and let me know id it is not.  Thanks.  </p>