[wellylug] bash / sed / awk tricky question
Glen Ogilvie
nelg at linuxsolutions.co.nz
Fri Feb 4 14:13:59 NZDT 2005
Hi,
I have a quite tricky scripting question. Anyone that feels like
a little bit of a challange... read on.
I am trying to write a shell / sed / awk script to read some file names
of rpm packages, and just get the latest one, which I will then setup
further on in a script to download. I could probally write a solution to
getting just the latest version name in php/perl, however, think it would
be great to know how to do with some of the other more common linux tools.
Here is a shortened sample of the file names
liblibinstpatch0-1.0.0beta_20041028-1.mdk10.1.thac.i586.rpm
liblibinstpatch0-devel-1.0.0beta_20041028-1.mdk10.1.thac.i586.rpm
liblilypond-2.3.25-1thac.i586.rpm
liblilypond-2.4.2-1thac.i586.rpm
liblilypond-2.5.2-1thac.i586.rpm
liblo0-0.13-1.mdk10.1.thac.i586.rpm
tkchooser2-0.65.2-3.mdk10.1.thac.i586.rpm
us428control-1.0.7-2.mdk10.1.thac.i586.rpm
us428control-1.0.8-0.rc2.3.mdk10.1.thac.i586.rpm
the script needs to return something like this... based on those file
names
liblibinstpatch0-1.0.0beta_20041028-1.mdk10.1.thac.i586.rpm
liblibinstpatch0-devel-1.0.0beta_20041028-1.mdk10.1.thac.i586.rpm
liblilypond-2.5.2-1thac.i586.rpm
liblo0-0.13-1.mdk10.1.thac.i586.rpm
tkchooser2-0.65.2-3.mdk10.1.thac.i586.rpm
us428control-1.0.8-0.rc2.3.mdk10.1.thac.i586.rpm
I.e., notice the too of the liblilypond packages, and one of the
additional us428 packages should be removed from this sample.
The real list is much bigger, so the rules need to do something like..
1. find the names before the first -number (note that mdk10 is not always
in the name)
2. print the name where the version number is the higest. (this might not
be the last one, depends on how 'sort' handles version numbers greater
than 9 )
Any suggestions of how do to this in a script would be appricated, as it
will help me learn some more complicated awk/sed scripting.
Thanks heaps anyone that takes this time to think about this.
Glen Ogilvie
More information about the wellylug
mailing list