title: Shell script for parsing log file
body: <p>I'm writing a shell script to parse through log file and pull out all instances where sudo succeeded and/or failed. I'm realizing now that this probably would've been easier with shell's equivalent of regex, but I didn't want to take the time to dig around (and now I'm paying the price). Anyway:</p>
  
  <pre><code>sudobool=0
  sudoCount=0
  
  for i in `cat /var/log/auth.log`;
  do
      for word in $i;
      do
          if $word == "sudo:"
          then
              echo "sudo found"
              sudobool=1;
              sudoCount=`expr $sudoCount + 1`;
          fi
      done
  
      sudobool=0;
  
  done
  
  
  echo "There were " $sudoCount " attempts to use sudo, " $sudoFailCount " of which failed."
  </code></pre>
  
  <p>So, my understanding of the code I've written: read auth.log and split it up line by line, which are stored in i. Each word in i is checked to see if it is sudo:, if it is, we flip the bool and increment. Once we've finished parsing the line, reset the bool and move to the next line.</p>
  
  <p>However, judging by my output, the shell is trying to execute the individual words of the log file, typically returning '$word : not found'.</p>