title: How to grep lines starting with a digit or white space
body: <p>I need to count messages per hour in my log file. Every log file line is preceded by the time stamp. Hence I am using following 'for' and 'grep' command to do this -</p>
  
  <pre><code>for i in `seq 0 23`
  do egrep "$i:[0-9][0-9]:[0-9][0-9] &lt;some_pattern&gt;" filename | wc -l
  done
  </code></pre>
  
  <p>This will give me number of messages per hour for 0 to 23.</p>
  
  <p>However this does not work with single digit hour such as <code>5:23:32</code> because it is preceded by a white space. Then the grep would have to be -</p>
  
  <pre><code>egrep " $i:[0-9][0-9]:[0-9][0-9] &lt;some_pattern&gt;" filename | wc -l
  </code></pre>
  
  <p>If not it will incorrectly match lines starting with say <code>15:23:32</code></p>
  
  <p>So how can I tell grep that a digit can be preceded by a space or start of the line only.</p>