Linux relevance help

(imported topic written by robbieb91)

I’m trying to check the version of an app, in this case openoffice.org. I am doing so by parsing a txt file that we dump the rpm database to. Here is the relevance I use to query the rpm txt file:

if (exists file “rpmtxtfile” whose (modification time of it < now - 2 * day)) and (exists line whose (it starts with “openoffice.org3-”) of file “rpmtxtfile”) then (((following text of firsts “openoffice.org3-” of lines whose (it contains “openoffice.org3-”) of file “rpmtxtfile”) as version) < (“3.2.1” as version)) else (exists package “openoffice.org3” whose (version of it < " of it) of rpm)

The issue I am having is that there are multiple instances of “openoffice.org3-” in the rpm txt file:

openoffice.org3-base-3.3.0-9567.x86_64

openoffice.org3-dict-fr-3.3.0-9567.x86_64

openoffice.org3-en-US-3.3.0-9567.x86_64

openoffice.org3-calc-3.3.0-9567.x86_64

openoffice.org3-3.3.0-9567.x86_64

q: following texts of firsts “openoffice.org3-” of lines whose (it contains “openoffice.org3-”) of file “rpmtxtfile” as version

a: base-3.3.0-9567.x86_64

What I need to have returned is the last value in the list: “openoffice.org3-3.3.0-9567.x86_64”, but more specifically, “3.3.0-9567.x86_64”

Any ideas on how to return the version information from the exact filename I need to use?

thanks,

(imported comment written by BenKus)

Do you need the last line? or the line that looks like openoffice.org3 (but without the -en-, -calc-, etc)?

Ben

(imported comment written by robbieb91)

Ben,

I’m looking for the instance without the -en, -calc, etc… And this is not the only example, so if there is a generic way to accomplish this, that would be great.

thanks!

(imported comment written by SystemAdmin)

Try replacing

following text of firsts “openoffice.org3-” of

with

following texts whose(“01234556789” contains first 1 of it) of firsts “-” of

If you have more examples, please go ahead and post them, as it may make it easier to come up with a good, general solution.

-Jim

(imported comment written by robbieb91)

Here are some more examples. The lines with ** are the lines that i would need.

thanks,

emacs-21.3-224.17.x86_64.rpm

emacs-info-21.3-224.17.x86_64.rpm

emacs-nox-21.3-224.17.x86_64.rpm

emacs-x11-21.3-224.17.x86_64.rpm

perl-32bit-5.8.8-14.10.x86_64.rpm

perl-5.8.8-14.10.x86_64.rpm

perl-AppConfig-1.56-43.2.x86_64.rpm

perl-Archive-Zip-1.16-13.2.x86_64.rpm

perl-Bit-Vector-6.4-13.5.x86_64.rpm

perl-Bootloader-0.4.19.21-0.4.12.x86_64.rpm

perl-Carp-Clan-5.3-13.5.x86_64.rpm

(imported comment written by BenKus)

You might use regular expressions, but it gets tricky…

Can you rely on the fact that there are always two “-” in the lines that you want?

q: following texts of firsts “-” of lines whose (number of substrings “-” of it = 2) of file "C:\temp\test.txt"
A: 21.3-224.17.x86_64.rpm
A: 5.8.8-14.10.x86_64.rpm

Ben

(imported comment written by SystemAdmin)

I came up with this, but was concerned about other cases which might not work. If you let me know what result you get from running this, then we can try to tweak it a bit more. The ‘32bit’ part of one of the Perl entries made me have to rethink my initial strategy, but I found a way to work around it:

Q: (item 0 of it, preceding text of first “-” of item 1 of it, following text of first “-” of item 1 of it) of (it, preceding texts of firsts “.x86” of it) of lines whose(“0123456789” contains first 1 of following text of first “-” of it AND “0123456789” contains last 1 of preceding text of first “-” of following text of first “-” of it) of file “c:\temp\test\rpmfilelist.txt”

A: openoffice.org3-3.3.0-9567.x86_64, openoffice.org3, 3.3.0-9567

A: emacs-21.3-224.17.x86_64.rpm, emacs, 21.3-224.17

A: perl-5.8.8-14.10.x86_64.rpm, perl, 5.8.8-14.10

Where “item 0 of it” is the initial string, “item 1 of it” is the name and “item 2 of it” is the version string.

-Jim

P.S. As I was about to post this, I noticed Ben has come up with a nice, succinct version. Oh well. :slight_smile:

(imported comment written by robbieb91)

@Ben, no, I cannot rely on the format of the string. :frowning:

@jwilkinson, i’ll give this a try today and let you know what happens.

@both, much appreciated help!!!