title: Bash - extract date from string and reformat
body: <p>In a bash script I'm trying to get the date of the last login from <code>last</code></p>
  
  <p>eg:</p>
  
  <pre><code>last bob -n 1
  </code></pre>
  
  <p>Which gives me:</p>
  
  <pre><code>bob     tty1    Fri Jul 18 10:43 - 10:43  (00:00)
  
  wtmp begins Wed Feb  5 17:47:13 2014
  </code></pre>
  
  <p>and then extract the date from that string, and insert it into the <code>lastb</code> to get the number of failed logins since last successful one.</p>
  
  <p>eg:</p>
  
  <pre><code>lastb bob -t $MYLASTLOGIN
  </code></pre>
  
  <p><a href="http://linux.die.net/man/1/lastb" rel="nofollow">man lastb</a> shows the date format needs to be <code>-t YYYYMMDDHHMMSS</code></p>