title: parsing ifconfig into lists
body: <p>I want to parse ifconfig so that I am only left with the vlans that have an IP address assigned.
  I want the following data from each vlan, the interface name, the IP address and the mac address (mac in a  converted format). These should be stored in a list of lists. A list for each vlan.</p>
  
  <p>So far I have just made one list with the IP and the interface name for each vlan. However I feel I am going off track and doing this in a bad way, any suggestions?</p>
  
  <p>Desired output:</p>
  
  <pre><code>[['vlan1', '192.168.2.2', '0013.F200.0058'], ['vlan100', '192.168.110.2','0013.F200.0058'], ['vlan20', '192.168.30.2','0013.F200.0058']]
  </code></pre>
  
  <p>Current output:</p>
  
  <pre><code> ['vlan1', '0013.F200.0058', '192.168.2.2', 'vlan100', '0013.F200.0058', '192.168.110.2', 'vlan20', '0013.F200.0058', '192.168.30.2']
  </code></pre>
  
  <p>I know I can turn this flat list into nested lists easily, but I feel it should be done in the step before this.</p>
  
  <p>EG but I think this is bad:</p>
  
  <pre><code>i=0
  new_list=[]
  while i&lt;len(data_list):
      new_list.append(data_list[i:i+3])
      i+=3
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import re
  a = """
  
  vlan1     Link encap:Ethernet  HWaddr 00:13:F2:00:00:58  
            inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:39 errors:0 dropped:0 overruns:0 frame:0
            TX packets:2708 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:2188 (2.1 KiB)  TX bytes:383156 (374.1 KiB)
  
  vlan100   Link encap:Ethernet  HWaddr 00:13:F2:00:00:58  
            inet addr:192.168.110.2  Bcast:192.168.110.255  Mask:255.255.255.0
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:2 errors:0 dropped:0 overruns:0 frame:0
            TX packets:2683 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:100 (100.0 B)  TX bytes:375620 (366.8 KiB)
  
  vlan2     Link encap:Ethernet  HWaddr 00:13:F2:00:00:58  
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:0 errors:0 dropped:0 overruns:0 frame:0
            TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
  
  vlan20    Link encap:Ethernet  HWaddr 00:13:F2:00:00:58  
            inet addr:192.168.30.2  Bcast:192.168.30.255  Mask:255.255.255.0
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:17274 errors:0 dropped:0 overruns:0 frame:0
            TX packets:16376 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:0 
            RX bytes:4389760 (4.1 MiB)  TX bytes:3112376 (2.9 MiB)
  """
  
      for paragraph in a.split('\n\n'):
  
      #mac = re.search(r'HWaddr\s+(\S+)', paragraph)
      #c.append(mac.group(1))
      if "vlan" in paragraph and "inet addr:" in paragraph:
          b= []
          b.append(paragraph.split())
          for i in b[0]:     
              if "addr:" in i:
                  ip = re.search(r'addr:(\S+)', i)
                  c.append(ip.group(1))
              if "vlan" in i:
                  c.append(i)   
              if  re.search(r'\d\d:\d\d:(\S+)', i):
                  it = iter(i.split(':'))
                  i = ".".join(x+y for x,y in zip(it,it))
                  c.append(i) 
       print c
  </code></pre>