title: Python: how to parse the output of a linux command using compile and split
body: <p>I need to write a script using re.compile and split to take in the cmd and print out the ip address(last col) and the date and time and convert it to epoch time.
  I was using just re.compile but was mentioned to me to use the split command to make it easier.. just looking for some guidance?
  this is what the output looks like</p>
  
  <pre><code>host:~ # last -a -F | egrep -v "boot|wtmp|tty"
  root     pts/2        Fri Jun 19 10:32:13 2015   still logged in                       xx.x.xx.xx
  root     pts/0        Fri Jun 19 08:22:29 2015   still logged in                       xx.xx.xx.xx
  root     pts/5        Thu Jun 18 10:09:30 2015 - Thu Jun 18 17:20:52 2015  (07:11)     xx.xx.xx.xx
  root     pts/4        Thu Jun 18 09:53:33 2015 - Thu Jun 18 17:04:53 2015  (07:11)     xx.xx.xx.xx
      last_re = re.compile(r'(?P&lt;user&gt;\S+)\s+(?P&lt;pts&gt;\/.+)\s(?P&lt;day&gt;\S+)\s+(?P&lt;month&gt;)\s+(?P&lt;date&gt;\d+)\s+(?P&lt;stime&gt;(\d\:\d)\s+(?P&lt;hyphen&gt;(\s|-)\s+(?P&lt;endtime&gt;(\d\:\d)\s+(?P&lt;user&gt;)\s+(?P&lt;duration&gt;(\(\d\:\d\))\s+(?P&lt;ipaddress&gt;(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)')
      cmd = 'last -a -F | egrep -v "boot|wtmp|tty"'
  
      try:
              status, output = commands.getstatusoutput(cmd)
              print last_re;
              if not status:
                      output_lines = output.split('\n')
                      m = last_re.search(output_lines[1])
                      if m:
                              print "&lt;day='%s' month='%s' time='%s' external_ip='%s'/&gt;" % (m.group('day'), m.group('month'), m.group('stime'), m.group('ipaddress'))
  </code></pre>