title: Using `awk` to print number of lines in file in the BEGIN section
body: <p>I am trying to write an awk script and before anything is done tell the user how many lines are in the file. I know how to do this in the END section but unable to do so in the BEGIN section.  I have searched SE and Google but have only found a half dozen ways to do this in the END section or as part of a bash script, not how to do it before any processing has taken place at all. I was hoping for something like the following:</p>
  
  <pre><code>#!/usr/bin/awk -f
  
  BEGIN{
          print "There are a total of " **TOTAL LINES** " lines in this file.\n"
       }
  {
  
          if($0==4587){print "Found record on line number "NR; exit 0;}
  }
  </code></pre>
  
  <p>But have been unable to determine how to do this, if it is even possible. Thanks.</p>