Shell - output for ifconfig


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:  Bcast:  Mask:
eth1      Link encap:Ethernet  HWaddr 00:50:56:8A:F5:F5  
          inet addr:  Bcast:  Mask:
lo        Link encap:Local Loopback  
          inet addr:  Mask:

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

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}'

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

some versions may prefer
awk -v W1=40 -v W2=30 -v W3=10 -v LC="\="
joaotellesAuthor Commented:
Tks. Any input on the formatting of the main command?

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;}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.