LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-28-2006, 01:53 PM   #1
allomeen
Member
 
Registered: Dec 2005
Posts: 83

Rep: Reputation: 15
Get Library Version Using AWK


Hello Everyone,

I need to be able to get the latest version of a library (lmylib.so.Major.Minor) using AWK or something.

The reason I need this because I have a script that will create a new library with a new version number depending in the last version I have of mylib.

I tried this "awk '{ print $9}' a.out" where a.out is ls -la /usr/local/lib but How do I get to the minor number from there?

Thanks in advance,
Alaa G
 
Old 04-28-2006, 02:56 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
What distro are you using?

major/minor refers to device files not libraries. I don't see the library you mention on my system so am not sure why you're expecting to see major/minor numbers.

Also remember compiled files are not pure text and awk is a text processor. You may have better results by typing:

strings filename |awk '{print $}'

The "strings" command prints the only the text within a binary to the output.
 
Old 04-28-2006, 03:35 PM   #3
allomeen
Member
 
Registered: Dec 2005
Posts: 83

Original Poster
Rep: Reputation: 15
I'm using fedora 5.

I don't mean the major and minor number of the device. I meant it for the libraries. If you go to /usr/local/lib or usr/lib and for example looked at "libpcap.so.0.8.3", the 8 means the major version and the 3 means minor version.

"a.out" is not an executable, I just called this way; it has the output of the command "ls -la /usr/local/lib"

so What I wanted to is to get all the links with mylib.so* and find the latest minor version so when I update my library I could increment automatically from the script.

Thanks
 
Old 05-01-2006, 03:00 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
OK got you now.

Looking in /usr/lib on my AS3 system I'll use libz.so.1.1.4 for example.

To see all the files that are related to libz.so.1.1.4
Code:
ls -l |grep libz.so.1.1.4
lrwxr-xr-x 1 root root 13 Aug 3 2005 libz.so -> libz.so.1.1.4
lrwxr-xr-x 1 root root 13 Aug 3 2005 libz.so.1 -> libz.so.1.1.4
-rwxr-xr-x 1 root root 52584 Sep 17 2003 libz.so.1.1.4

To get just the ones that are links you do it with:
Code:
ls -l |grep libz.so.1.1.4 |grep ^l
lrwxr-xr-x 1 root root 13 Aug 3 2005 libz.so -> libz.so.1.1.4
lrwxr-xr-x 1 root root 13 Aug 3 2005 libz.so.1 -> libz.so.1.1.4
In the above the grep for ^l (ell) tells it to look for an l in the first position as only a symbolic link would have that.

To get the name of the file that was linked do this:
Code:
ls -l |grep libz.so.1.1.4 |grep ^l |cut -c57- |awk '{print $1}'
libz.so
libz.so.1

The "cut -c57-" says to get everything from position 57 to end of line. This would be the file name and the file to which it is linked along with the "->". The reason to do cut rather than awk is that it will be position 57 regardless of whether the date on the file is a full date or just a time stamp but the number of fields in a file (as seen by awk) would vary if it were a date rather than a time stamp. (Note this position is consistent within an operating system but can be different from one OS to the next so you should always count to be sure of the number.) Once the cut is done you do awk to get only the first part of the output from the cut which is the file name. Here the opposite is true - the position varies but the field count doesn't so this is why awk is appropriate here.

Last edited by MensaWater; 05-01-2006 at 03:02 PM.
 
Old 05-02-2006, 12:13 PM   #5
allomeen
Member
 
Registered: Dec 2005
Posts: 83

Original Poster
Rep: Reputation: 15
Thank you so much for your help. I ended up using this command

"ls -l libz.so.1.1.4 | awk '{print $9}' | sort |awk -F. '{print $5}' | tail --lines=1 | awk '{print $1 + 1}' " --> this will give you the new version number of the library. I used this command from the make file, but you have to use $$9 instead because $ is a keyword in Makefiles

Last edited by allomeen; 05-02-2006 at 05:11 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
list library function of a shared library .so powah Linux - General 7 10-25-2011 04:47 AM
Regarding distribution + kernel version + gcc version + glib version. JCipriani Linux - General 8 04-19-2008 02:54 PM
Shared Library Version rahul_kulkarni Linux - Newbie 1 02-22-2005 05:40 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
what is the function library of the basic graphics library in rethat9.0? zerwolve Red Hat 0 04-29-2004 09:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration