Shell - list only symbolic links

Hi,

Im trying to manipulate an output for a command but I dont see to be getting it right..

Basically what I want to do is list only the symbolic links and them format the output to a table:

The first ls is this one:

> ls -la
total 148
lrwxrwxrwx  1 root root      14 May 12 22:11 addfs -> ../addfs_3.2.0
drwxr-xr-x  8 dpa  dpgrpa  4096 Apr 14 21:05 backup
drwxr-xr-x  2 dpa  dpgrpa 12288 May 12 22:11 bin
lrwxrwxrwx  1 root root      33 May 12 22:11 boa -> /opt/smarttrust/dpa/bom_6.4.2/boa
lrwxrwxrwx  1 root root      33 May 12 22:11 bom -> /opt/smarttrust/dpa/bom_6.4.2/bom
lrwxrwxrwx  1 root root      24 May 12 22:11 campaignmanager -> ../campaignmanager_4.2.0
lrwxrwxrwx  1 root root      12 May 12 22:11 cca -> ../cca_6.2.0
drwxr-xr-x  2 dpa  dpgrpa  4096 Apr 14 21:05 clientcacerts
drwxr-xr-x  3 dpa  dpgrpa  4096 Apr 14 21:05 clientcerts
lrwxrwxrwx  1 root root      16 May 12 22:11 cluster -> ../cluster_2.1.0
drwxr-xr-x  2 dpa  dpgrpa 12288 May 12 22:11 config


Then I came up with this command:

>ls -la | grep "\->" |awk '{$1=$2=$3=$4=$5=$6=$7=$8=$9=$10=""; print $0}'  --  (there are for sure better options to achieve that)
          ../addfs_3.2.0
          /opt/smarttrust/dpa/bom_6.4.2/boa
          /opt/smarttrust/dpa/bom_6.4.2/bom
          ../campaignmanager_4.2.0
          ../cca_6.2.0
          ../cluster_2.1.0

And with this output I would like to have this:

Products                     Version
============================
addfs                           3.2.0              
bom                             6.4.2
campaignmanager    4.2.0
cca                                6.2.0
.


Some problems I had were the lines differ on their prefix... (../addfs_3.2.0 and /opt/smarttrust/dpa/bom_6.4.2/boa). So I couldnt figure a way to have it formatted into the table above...

Is it possible to do what Im trying to do..?

Tks,
Joao
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.

simon3270Commented:
If you assume that none of the filenames or paths has a space in it (they really shouldn’t for system files like this!), and there is only one entry with an underscore in the target path, then

ls -la | awk '/->/{print $11}' | sed 's,.*/\([a-z][a-z]*\)_\([0-9][0-9.]*\).*,\1 \2,' | sort -u

Then you just have to add the headers.
0

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.