title: How to format output of ifconfig
body: <p>I need to transfom the result of command <code>ifconfig -a</code> to the following format </p>
  
  <pre><code>IFACE eth0 192.168.30.8 Ethernet
  IFACE eth1 212.233.112.171 Ethernet
  IFACE lo 127.0.0.1 Local Loopback 
  IFACE pan0 0.0.0.0 Ethernet
  IFACE tunl0 0.0.0.0 IPIP Tunnel
  </code></pre>
  
  <p>I know that I should do that with the <code>sed</code> or something similar.
  For now I have the following "script":</p>
  
  <pre><code>ifconfig -a | sed -r -n -e 'N' -e 's/(\w+)(\s*)(Link\sencap:)(\w+(\s\w+)*)([^\n]*)\n\s+(inet\saddr:)([0-9]{1,3}(\.[0-9]{1,3}){3}).*/IFACE \1 \8 \4/p'
  </code></pre>
  
  <p>The original <code>ifconfig -a</code> output is (<code>...</code> means ommited parts) </p>
  
  <pre><code>eth0      Link encap:Ethernet  HWaddr f4:ce:46:99:22:57
            inet addr:192.168.30.8  Bcast:192.168.31.255  Mask:255.255.254.0
            ...
  eth1      Link encap:Ethernet  HWaddr 00:23:7d:fd:a2:d0
            inet addr:212.233.112.171  Bcast:212.233.112.175  Mask:255.255.255.240
            ...
  lo        Link encap:Local Loopback
            inet addr:127.0.0.1  Mask:255.0.0.0
            ...
  pan0      Link encap:Ethernet  HWaddr f6:d0:8a:0e:7b:95
            BROADCAST MULTICAST  MTU:1500  Metric:1
            ...
  tunl0     Link encap:IPIP Tunnel  HWaddr
            NOARP  MTU:1480  Metric:1
            ...
  </code></pre>
  
  <p><strong>The first problem</strong> with this transformation is that IP address resides on the second line from the interface name and type. A used the <code>-N</code> argument to concat the lines, but they are being concat in pairs, and if the name of the interface is on odd line - I have troubles: script skips the interface on the odd line, like this (NOTE that there are no mentioning about pan0 in the output.):</p>
  
  <pre><code>IFACE eth0 192.168.30.8 Ethernet 
  IFACE eth1 212.233.112.171 Ethernet 
  IFACE lo 127.0.0.1 Local Loopback
  IFACE tunl0 IPIP Tunnel
  </code></pre>
  
  <p><strong>The second problem</strong> is that I don't know how to insert zero-address when there are no IP adress in <code>ifconfig -a</code> output.</p>