Shell - output for ifconfig

Hi,

Im trying to format the output for a ifconfig -a command but Im having problems with it (prob. because Im a newbie with shell scripting)...

Anyway, here is what I have now: (not much)

# ifconfig -a | grep 'encap\|addr' | grep -v 'IPv6-in-IPv4' | grep -v "inet6 addr"
eth0      Link encap:Ethernet  HWaddr 00:50:56:8A:F5:F4  
          inet addr:10.216.209.69  Bcast:10.216.209.255  Mask:255.255.255.0
eth1      Link encap:Ethernet  HWaddr 00:50:56:8A:F5:F5  
          inet addr:192.168.1.69  Bcast:192.168.1.255  Mask:255.255.255.0
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0


Im having a few problems with this:

1- The output Im looking for is:

Interface     Link                MAC Addr                      IP                          Broadcast                     Netmask  
==================================================================================
eth0            Ethernet       00:50:56:8A:F5:F4      10.216.209.69         10.216.209.255          255.255.255.0
.
.

For all interfaces listed... the thing is that im struggling to get the first output in the right format... any suggestion?


PS: For the columns setup I plan to use this: (Help from other question I have opened yesterday!)

< command >  |  awk -v W1=40 -v W2=30 -v W3=10 -v LC="=" '
    BEGIN {FORMAT="%-"W1"s%-"W2"s%-"W3"s\n";
           printf FORMAT,"Package","Version","Status";
           while (L++<W1+W2+W3) R=R LC; print R
         } !/^Unable/ {printf FORMAT,$1,$2,$3}'


Tks,
Joao
joaotellesAsked:
Who is Participating?
 
ozoCommented:
awk -v W1=10 -v W2=20 -v W3=30 -v W4=20 -v W5=20 -v W6=20 -v LC="=" '
    BEGIN {FORMAT="%-"W1"s%-"W2"s%-"W3"s%-"W4"s%-"W5"s%-"W6"s\n";
           printf FORMAT,"Interface","Link","MAC Addr","IP","Broadcast","Netmask";
           while (L++<W1+W2+W3+W4+W5+W6) R=R LC; print R
         }
{for(i=1;i<=NF;++i){split($i, a,/:/);f[a[1]]=a[2]} }
/^ /{printf FORMAT,f1,f["encap"],f3,f["addr"],f["Bcast"],f["Mask"];delete f;}
!/^Unable/{f1=$1;f3=$NF}'
0
 
ozoCommented:
some versions may prefer
awk -v W1=40 -v W2=30 -v W3=10 -v LC="\="
0
 
joaotellesAuthor Commented:
Tks. Any input on the formatting of the main command?

Tks,
Joao
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.