Shell - output of a command into a table

Hi,

Im running this command but Im struggling to find the optimal way to have its output as a formatted table...

yum list all | tail -n +4
Unable to read consumer identity
Deployment_Guide-en-US.noarch              5.8-1.el5                   installed
MAKEDEV.x86_64                             3.23-1.2                    installed
NetworkManager.i386                        1:0.7.0-13.el5              installed
NetworkManager.x86_64                      1:0.7.0-13.el5              installed


I wanted to format the output into a table like:  ----> I have attached the output as well..

Package                                    Version                     Status
====================================================================================
Deployment_Guide-en-US.noarch              5.8-1.el5                   installed
MAKEDEV.x86_64                             3.23-1.2                    installed
NetworkManager.i386                        1:0.7.0-13.el5              installed
NetworkManager.x86_64                      1:0.7.0-13.el5              installed


Note that I need to ignore the warning line for the yum command... (Unable to read consumer identity)

Tks,
Joao
output.txt
joaotellesAsked:
Who is Participating?

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

x
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.

woolmilkporcCommented:
Here is good old awk:

yum list all | tail -n +4 |
awk -v W1=40 -v W2=24 -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}'

Open in new window

W1/W2/W3 are the column widths which you can adjust as desired.
LC is the character to form the separator line (=). Change at taste.

Add "> output.txt" at the end to create the output file.

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.