Read a log file and get the version of the app (substring)

Hello,

I’m trying to get the version of the following apps using the following log file:

//Start log file

Name                   : Microsoft.DesktopAppInstaller
Publisher              : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Architecture           : X64
ResourceId             : 
Version                : 1.16.13405.0

//end log file

I’m using the following relevance to read it:

if (exist file “C:\hp\logs\MicrosoftAppInstaller.log”) then concatenation “,” of (following texts of firsts"Version :" of lines whose (it starts with “Version :”) of file “C:\hp\logs\MicrosoftAppInstaller.log”) else “not found”

However, I’m getting a blank result instead of “1.16.13405.0”.

I’m using the same analysis but using a different file ( without spaces ) and it’s working fine.
I’m not sure if the issue is related to the spaces.

Here are some screen-shots:

Any idea why it’s not showing the version?

Thank you

You’re searching for “Version :”, with one space between Version and the colon, but the file has an unknown number of spaces (or tabs) between the version and the colon. Try

following texts of firsts ":" of lines whose (it starts with "Version")

I tried with

if (exist file “C:\hp\logs\MicrosoftAppInstaller.log”) then concatenation “,” of (following texts of firsts “:” of lines whose (it starts with “Version”) of file “C:\hp\logs\MicrosoftAppInstaller.log”) else “not found”

but it did not work.

Also, I tried with spaces but Im getting the same result:

following texts of firsts “:” of lines whose (it starts with "Version ") of file “C:\hp\logs\MicrosoftAppInstaller.log”

Thank you Jason

Strange, it seems to work for me…

q: lines of file "c:\temp\log.txt"
A: Name                   : Microsoft.DesktopAppInstaller
A: Publisher              : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
A: Architecture           : X64
A: ResourceId             : 
A: Version                : 1.16.13405.0
T: 15.995 ms
I: plural file line

q: if (exist file "C:\temp\log.txt") then concatenation "," of (following texts of firsts ":" of lines whose (it starts with "Version") of file "C:\temp\log.txt") else "not found"
A:  1.16.13405.0
T: 15.573 ms
I: singular string

Does your file actually have spaces before the “Version” string? Maybe try trimming the line before searching for ‘Version’ (and also trimming the version value after retrieving it to remove the extra spaces)?

q: if (exist file "C:\temp\log.txt") then concatenation "," of (following texts of firsts ":" of lines whose (it as trimmed string starts with "Version") of file "C:\temp\log.txt" as trimmed string) else "not found"
A: 1.16.13405.0
T: 0.754 ms
I: singular string
1 Like

Your file looks very neatly aligned, which may mean spaces or may mean tabs, so I’d start by finding out exactly what is in there

I copied your content above, then lined it up with a mix of spaces & tabs (as you can see below)

q: lines of file "c:\trn\testlog.txt"
A: //Start log file
A: 
A: Name  %09%09:%09Microsoft.DesktopAppInstaller
A: Publisher       :       CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
A: Architecture    :       X64
A: ResourceId      :
A: Version%09%09:%091.16.13405.0
A: 
A: //end log file
I: plural file line

q: lines whose (it contains ":") of file "c:\trn\testlog.txt"
A: Name  %09%09:%09Microsoft.DesktopAppInstaller
A: Publisher       :       CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
A: Architecture    :       X64
A: ResourceId      :
A: Version%09%09:%091.16.13405.0
I: plural file line

q: lines whose (it contains "%20") of file "c:\trn\testlog.txt"
A: //Start log file
A: Name  %09%09:%09Microsoft.DesktopAppInstaller
A: Publisher       :       CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
A: Architecture    :       X64
A: ResourceId      :
A: //end log file
I: plural file line

q: lines whose (it contains "%09") of file "c:\trn\testlog.txt"
A: Name  %09%09:%09Microsoft.DesktopAppInstaller
A: Version%09%09:%091.16.13405.0
I: plural file line

q: ("|" & it as trimmed string & "|") of substrings separated by ":" of lines whose (it contains ":") of file "c:\trn\testlog.txt"
A: |Name|
A: |Microsoft.DesktopAppInstaller|
A: |Publisher|
A: |CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US|
A: |Architecture|
A: |X64|
A: |ResourceId|
A: ||
A: |Version|
A: |1.16.13405.0|
I: plural string

q: concatenation "," of (it as trimmed string) of following texts of firsts ":" of lines whose (it starts with "Version") of file "c:\trn\testlog.txt"
A: 1.16.13405.0
I: singular string

Once you know what is in there, you can start to parse it.

That said, I can’t see why Jason’s code didn’t work because it isn’t using white space of any kind as a delimiter - perhaps there is a non-printing character before ‘Version’ or you have a file with some weird encoding

1 Like