title: awk: find minimum and maximum in column
body: <p>I'm using <strong><a href="http://www.gnu.org/software/gawk/manual/gawk.html" rel="noreferrer">awk</a></strong> to deal with a simple .dat file, which contains several lines of data and each line has 4 columns separated by a single space. 
  I want to find the minimum and maximum of the first column. </p>
  
  <p>The data file looks like this: </p>
  
  <pre><code>9 30 8.58939 167.759
  9 38 1.3709 164.318
  10 30 6.69505 169.529
  10 31 7.05698 169.425
  11 30 6.03872 169.095
  11 31 5.5398 167.902
  12 30 3.66257 168.689
  12 31 9.6747 167.049
  4 30 10.7602 169.611
  4 31 8.25869 169.637
  5 30 7.08504 170.212
  5 31 11.5508 168.409
  6 31 5.57599 168.903
  6 32 6.37579 168.283
  7 30 11.8416 168.538
  7 31 -2.70843 167.116
  8 30 47.1137 126.085
  8 31 4.73017 169.496
  </code></pre>
  
  <p>The commands I used are as follows. </p>
  
  <pre><code>min=`awk 'BEGIN{a=1000}{if ($1&lt;a) a=$1 fi} END{print a}' mydata.dat`
  max=`awk 'BEGIN{a=   0}{if ($1&gt;a) a=$1 fi} END{print a}' mydata.dat`
  </code></pre>
  
  <p>However, the output is <strong>min=10</strong> and <strong>max=9</strong>. </p>
  
  <p>(The similar commands can return me the right minimum and maximum of the second column.)</p>
  
  <p>Could someone tell me where I was wrong? Thank you!</p>