Relevance, version checking, but with blank value

(imported topic written by SystemAdmin)

In the relevance below, how could I make it result in false if the value after C: was blank “ “, it currently evaluates to True using the following.

exists file “/opt/sni/unix/etc/bladeinfo” AND (following text of first “:” of lines whose (it starts with “C:”) of file “/opt/sni/unix/etc/bladeinfo” as version < ")

Contents of file: bladeinfo

rdcbc006mm

05

uxpfm220

HS22

B:1.09

D:3.10

S:1.14

C: <-Value is blank or No cKVM module installed

E:enabled

(imported comment written by JackCoates91)

there’s probably a better way to do it, but this seems to work:

q: exists file "c:\users\jack\desktop\bladeinfo.txt" AND (if (following text of first ":" of (lines whose (it starts with "C:") of file "c:\users\jack\desktop\bladeinfo.txt" as trimmed string) contains "1") then (following text of first ":" of lines whose (it starts with "C:") of file "c:\users\jack\desktop\bladeinfo.txt" as version < ") else (false))

the trick is an if then loop which checks that the string has something in it at all, which I’m currently testing for “1”. In theory we shouldn’t need to do this because the “as trimmed string” should have killed the white space out of that value, but there’s still a carriage return or something causing it to need a further test.

(imported comment written by Trailsuender)

how to code this if I do not want to count lines beginning witn #.

typical for unix config files or so…

(imported comment written by jgstew)

See the answer here:
https://www.ibm.com/developerworks/community/forums/html/topic?id=82c2c01a-f9f4-4fba-b332-6f96bf7e1d4e

(imported comment written by NoahSalzman)

This should work too. Any time you see “else false” there is probably a way to do it without an if statement.

(exists file “/opt/sni/unix/etc/bladeinfo”) and ((length of it > 0 and it as version < ") of (following text of first “:” of lines whose (it starts with “C:”) of file “/opt/sni/unix/etc/bladeinfo”))

(imported comment written by JackCoates91)

Thanks, Noah, that’s definitely neater! I had tried length > 0 unsuccessfully, it may need contains “1” instead.

(imported comment written by NoahSalzman)

Hmmm… yeah, my contribution will fail if there are spaces or if the line ending somehow gets counted in the length. We should add your trimmed string idea:

(exists file “/opt/sni/unix/etc/bladeinfo”) and ((length of (it as trimmed string) > 0 and it as version < ") of (following text of first “:” of lines whose (it starts with “C:”) of file “/opt/sni/unix/etc/bladeinfo”))