I have a really tricky question. I need to parse a firmware install log file for the software installed, which could (but not always) appear at multiple locations in the file. Then I would like to find the last entry, and grab the the version number (which are not on the same line as the product name)
Example - I want to get the last HP Network Configuration Utility for Windows Server 2008 R2 installed entry in text file C:\cpqsystem\log\cpqsetup.log
It might also be HP Network Configuration Utility for Windows Server 2003 as name.
Setup Session Beginning 7/17/2010 - 11:42:09 AM
Command Line Parameters Given: /force /silent
Name: HP Network Configuration Utility for Windows Server 2008 R2 <------------------- this information
New Version: 10.0.0.0 <------------------- this information
Setup Session Beginning 2011-05-20 - 07:35:24
Command Line Parameters Given: /silent
Name: HP Network Configuration Utility for Windows Server 2008 R2 <------------------- this information
New Version: 10.30.0.0 <------------------- this information
If I understand you correctly, the following might work.
I have left the build up statements as examples. The last relevance statement is the one we want with some error checking included.
q: lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file "c:\cpqsystem\log\cpqsetup.log"
A: Name: HP Network Configuration Utility for Windows Server 2008 R2
A: Name: HP Network Configuration Utility for Windows Server 2008 R2
q: line numbers of lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file "c:\cpqsystem\log\cpqsetup.log"
A: 6
A: 17
q: maximum of (it as integer + 1) of line numbers of lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file "c:\cpqsystem\log\cpqsetup.log"
A: 18
q: lines whose (line number of it = maximum of (it as integer + 1) of line numbers of lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file “c:\cpqsystem\log\cpqsetup.log”) of file "c:\cpqsystem\log\cpqsetup.log"
A: New Version: 10.30.0.0
q: (it as trimmed string) of following text of first “New Version:” of lines whose (line number of it = maximum of (it as integer + 1) of line numbers of lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file “c:\cpqsystem\log\cpqsetup.log”) of file "c:\cpqsystem\log\cpqsetup.log"
A: 10.30.0.0
q: if (exists file “c:\cpqsystem\log\cpqsetup.log” and exists lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file “c:\cpqsystem\log\cpqsetup.log”) then ((it as trimmed string) of following text of first “New Version:” of lines whose (line number of it = maximum of (it as integer + 1) of line numbers of lines whose (it contains “HP Network Configuration Utility for Windows Server 2008 R2”) of file “c:\cpqsystem\log\cpqsetup.log”) of file “c:\cpqsystem\log\cpqsetup.log”) else (“Not applicable”)
A: 10.30.0.0
That was exactly what I was looking for, except that in the relevance debugger it runs for 25 seconds… Not a good one too kick out on all my environment to see latest firmware versions at a glance.
Thanks anyways, now I know how to do it, and should be able to move on.
Currerntly the expression runs an N squared operation (for every line of the file, it has to re-read every line of the file). Here is a different rendition of the same expression, that just first finds the line numbers, then just prints out the lines (basically just reads the file twice)
(
it as trimmed string
)
of following text of first "New Version:" of
(
item 1 of it
)
of
(
item 1 of it, lines of item 0 of it
)
whose
(
line number of item 1 of it = item 0 of it
)
of
(
it,
(
maximum of
(
line number of it + 1
)
of lines
whose
(
it contains "HP Network Configuration Utility for Windows Server 2008 R2"
)
of it
)
)
of file "c:\test.txt"
Using the above example, I was able to construct relevance to return the last 100 lines of a log file. Some log files can grow extremely large, and it would be a bad idea to report 1000+ lines into an analysis property, and it is very likely that you only care about the newest lines with the most recent log entries.
I have been working with Zaks code, but i have found that on some logs the information is on the second line from the search results. So I am trying to double Zaks code so that I have
line number of it + 1
OR
line number of it + 2
My code looks like this so far, but is only showing results from the first item
If (exists file “C:\cpqsystem\log\cpqsetup.log”) THEN ((it as trimmed string) of following text of first “New Version:” of (item 1 of it) of (item 1 of it, lines of item 0 of it) whose (line number of item 1 of it = item 0 of it) of (it, (maximum of (line number of it + 2) of lines whose (it contains “HP ProLiant iLO 2 Management Controller Driver for Windows”) of it)) of file “C:\cpqsystem\log\cpqsetup.log”) ELSE ((it as trimmed string) of following text of first “New Version:” of (item 1 of it) of (item 1 of it, lines of item 0 of it) whose (line number of item 1 of it = item 0 of it) of (it, (maximum of (line number of it + 1) of lines whose (it contains “HP ProLiant iLO 2 Management Controller Driver for Windows”) of it)) of file “C:\cpqsystem\log\cpqsetup.log”)
I threw in the If (exists file “C:\cpqsystem\log\cpqsetup.log”) only to avoid getting the boolean error. I know this is wrong, but I am not sure how to work around it.