Analysis relevance to extract multiple text

Hey everyone.

I am trying to extract some specific text from a txt file c:\hp-bios.txt, for example the file contains:

Prompt for Admin password on F11 (System Recovery)
*Disable
Enable
Prompt for Admin password on F12 (Network Boot)
*Disable
Enable
Wake on LAN Power-on Password Policy
Bypass Password
*Require Password
TPM Specification Version
1.2
TPM Device
Hidden
*Available
Embedded LAN controller
Disable
*Enable
Wake On LAN
Boot to Normal Boot Order
Disabled
Boot to Network
*Boot to Hard Drive
Internal Speakers
Disable
*Enable
Runtime Power Management
Disable
*Enable

I want to export the lines that contain the word “wake on lan” followed by the option that starts with an asterisk.

so for this example I would like to output:

Wake on LAN Power-on Password Policy
*Require Password
Wake On LAN
*Boot to Hard Drive

I am trying to create an analysis that will show me which options are set.

The best I can do is to output all the lines that contain ‘wake on lan’ so I can at least see what the matching options in the bios are:

concatenation "; " of lines whose (it as lowercase contains “wake on lan”) of file “C:\hp-bios.txt”
image

and this is what the actual file looks like:

Let me know if I need to provide more details.

Thanks!

We certainly could parse the text output, but the fact you’ve exported the text at all makes me think you’ve probably installed the HP Client Management interfaces ( https://developers.hp.com/hp-client-management/doc/client-management-script-library ) and could probably do WMI queries for these directly?

I’m using the HP bios configuration utility to export the BIOS settings to c:, then I just want to see if bf can get me the settings that are applied so I can then import the settings enabling wol. But I was looking over the hpbcu documentation and I can enter all the different types of wol options on a single file. I can mass push this to all hp workstations and they will only accept the setting that it applies to them and ignore the others. So I might not need to parse the text anymore but it would be cool to know if it’s possible

There was a Challenge a while back for reading ‘stanzas of a file’ which is very similar to this case. Several solutions at Relevance Challenge December 2019 BONUS: Parsing Paragraphs (answer provided)

I should be able to take a look a bit later if that doesn’t help.

Of the several options that are there, I think the one I prefer is the where we concatenate all the lines of the file together, marking which lines constitute the “start of a section”; then split the resulting single large string based on these marked “start of a section”.

As we are combining these lines in strings, we need to ensure that we don’t use delimiters that are likely going to appear in the original strings, else we can’t tell “our delimiters” from things that are part of the actual string data. Commonly I see “|” or “|||” used. Personally I prefer to use the Carriage Return and Line Feed characters, %0d and %0a, because our ‘lines of file’ inspecter would have naturally split lines on these characters already.

// printing the original file.  Note the lines that start with tabs are represented by '%09'
q: lines of file "c:\temp\hp.txt"
A: Prompt for Admin password on F11 (System Recovery)
A: %09*Disable
A: %09Enable
A: Prompt for Admin password on F12 (Network Boot)
A: %09*Disable
A: %09Enable
A: Wake on LAN Power-on Password Policy
A: %09Bypass Password
A: %09*Require Password
A: TPM Specification Version
A: %091.2
A: TPM Device
A: %09Hidden
A: %09*Available
A: Embedded LAN controller
A: %09Disable
A: %09*Enable
A: Wake On LAN
A: %09Boot to Normal Boot Order
A: %09Disabled
A: %09Boot to Network
A: %09*Boot to Hard Drive
A: Internal Speakers
A: %09Disable
A: %09*Enable
A: Runtime Power Management
A: %09Disable
A: %09*Enable
T: 3.206 ms

// We can concatenate all the lines together with our own character delimiter.  I prefer using %0a because this is the "line feed" character, so it should not appear as a literal in the string.

q: concatenation "%0a" of lines of file "c:\temp\hp.txt"
A: Prompt for Admin password on F11 (System Recovery)%0a%09*Disable%0a%09Enable%0aPrompt for Admin password on F12 (Network Boot)%0a%09*Disable%0a%09Enable%0aWake on LAN Power-on Password Policy%0a%09Bypass Password%0a%09*Require Password%0aTPM Specification Version%0a%091.2%0aTPM Device%0a%09Hidden%0a%09*Available%0aEmbedded LAN controller%0a%09Disable%0a%09*Enable%0aWake On LAN%0a%09Boot to Normal Boot Order%0a%09Disabled%0a%09Boot to Network%0a%09*Boot to Hard Drive%0aInternal Speakers%0a%09Disable%0a%09*Enable%0aRuntime Power Management%0a%09Disable%0a%09*Enable
T: 2.782 ms

// We can differentiate between "a line that starts a new section" versus "a line within the section".
// Assume a line that starts with a tab ( %09 ) is a line within a section, and a line that does not start with a tab is the start of a new section.
// If the line is the start of a section, prefix the line with a special separator character %0d (Carriage Return).

q: concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"
A: %0dPrompt for Admin password on F11 (System Recovery)%0a%09*Disable%0a%09Enable%0a%0dPrompt for Admin password on F12 (Network Boot)%0a%09*Disable%0a%09Enable%0a%0dWake on LAN Power-on Password Policy%0a%09Bypass Password%0a%09*Require Password%0a%0dTPM Specification Version%0a%091.2%0a%0dTPM Device%0a%09Hidden%0a%09*Available%0a%0dEmbedded LAN controller%0a%09Disable%0a%09*Enable%0a%0dWake On LAN%0a%09Boot to Normal Boot Order%0a%09Disabled%0a%09Boot to Network%0a%09*Boot to Hard Drive%0a%0dInternal Speakers%0a%09Disable%0a%09*Enable%0a%0dRuntime Power Management%0a%09Disable%0a%09*Enable
T: 2.337 ms

// Now that we know each "section" starts with a %0d character, we can split our string into sections by splitting on the %0d character.


q: substrings separated by "%0d" of concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"
A: 
A: Prompt for Admin password on F11 (System Recovery)%0a%09*Disable%0a%09Enable%0a
A: Prompt for Admin password on F12 (Network Boot)%0a%09*Disable%0a%09Enable%0a
A: Wake on LAN Power-on Password Policy%0a%09Bypass Password%0a%09*Require Password%0a
A: TPM Specification Version%0a%091.2%0a
A: TPM Device%0a%09Hidden%0a%09*Available%0a
A: Embedded LAN controller%0a%09Disable%0a%09*Enable%0a
A: Wake On LAN%0a%09Boot to Normal Boot Order%0a%09Disabled%0a%09Boot to Network%0a%09*Boot to Hard Drive%0a
A: Internal Speakers%0a%09Disable%0a%09*Enable%0a
A: Runtime Power Management%0a%09Disable%0a%09*Enable
T: 1.357 ms

// That previous split left a blank line, so we can exclude that one.  Now we have a unique result for each section of the file.

q: substrings separated by "%0d" whose (it != "") of concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"
A: Prompt for Admin password on F11 (System Recovery)%0a%09*Disable%0a%09Enable%0a
A: Prompt for Admin password on F12 (Network Boot)%0a%09*Disable%0a%09Enable%0a
A: Wake on LAN Power-on Password Policy%0a%09Bypass Password%0a%09*Require Password%0a
A: TPM Specification Version%0a%091.2%0a
A: TPM Device%0a%09Hidden%0a%09*Available%0a
A: Embedded LAN controller%0a%09Disable%0a%09*Enable%0a
A: Wake On LAN%0a%09Boot to Normal Boot Order%0a%09Disabled%0a%09Boot to Network%0a%09*Boot to Hard Drive%0a
A: Internal Speakers%0a%09Disable%0a%09*Enable%0a
A: Runtime Power Management%0a%09Disable%0a%09*Enable
T: 1.840 ms

// Now that each section is a separate result, we can split up the section so "everything before the first %0a is the section name", and "when split on %0a, the selected value is the one that begins with a tab and asterisk"

q: (preceding text of first "%0a" of it, substrings separated by "%0a" whose (it starts with "%09*") of it) of substrings separated by "%0d" whose (it != "") of concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"
A: Prompt for Admin password on F11 (System Recovery), %09*Disable
A: Prompt for Admin password on F12 (Network Boot), %09*Disable
A: Wake on LAN Power-on Password Policy, %09*Require Password
A: TPM Device, %09*Available
A: Embedded LAN controller, %09*Enable
A: Wake On LAN, %09*Boot to Hard Drive
A: Internal Speakers, %09*Enable
A: Runtime Power Management, %09*Enable
T: 0.815 ms

And, if you'd like to split off the tab-asterisk combination on the selected option we can do that; or manipulate the strings any other way you'd like.

q: (preceding text of first "%0a" of it, (following text of first "%09*" of it) of substrings separated by "%0a" whose (it starts with "%09*") of it) of substrings separated by "%0d" whose (it != "") of concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"
A: Prompt for Admin password on F11 (System Recovery), Disable
A: Prompt for Admin password on F12 (Network Boot), Disable
A: Wake on LAN Power-on Password Policy, Require Password
A: TPM Device, Available
A: Embedded LAN controller, Enable
A: Wake On LAN, Boot to Hard Drive
A: Internal Speakers, Enable
A: Runtime Power Management, Enable

Oh, and finally, we could get a result for any one specific setting by filtering on ‘item 0 of it’. We can either get the setting & value as a tuple, or just the value for the setting:

q: (preceding text of first "%0a" of it, (following text of first "%09*" of it) of substrings separated by "%0a" whose (it starts with "%09*") of it) whose (item 0 of it = "Wake on LAN Power-on Password Policy") of substrings separated by "%0d" whose (it != "") of concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"

A: Wake on LAN Power-on Password Policy, Require Password
T: 1.541 ms

q: items 1 of (preceding text of first "%0a" of it, (following text of first "%09*" of it) of substrings separated by "%0a" whose (it starts with "%09*") of it) whose (item 0 of it = "Wake on LAN Power-on Password Policy") of substrings separated by "%0d" whose (it != "") of concatenation "%0a" of (if it starts with "%09" then it else "%0d" & it) of lines of file "c:\temp\hp.txt"

A: Require Password
T: 0.779 ms
2 Likes

Jason thanks for that link - but that one is waaaaaaaay over my head. Your follow up posts does make more sense when I read it.

It think this one will work me as it outputs the setting and selected configuration:

I just make a slight edit to include all settings with ‘wake’ on it

Q: (preceding text of first “%0a” of it, (following text of first “%09*” of it) of substrings separated by “%0a” whose (it starts with “%09*”) of it) whose (item 0 of it contains “Wake”) of substrings separated by “%0d” whose (it != “”) of concatenation “%0a” of (if it starts with “%09” then it else “%0d” & it) of lines of file “c:\hp-bios.txt”

A: Wake On LAN, Boot to Hard Drive
A: Wake on LAN Power-on Password Policy, Bypass Password

I’ll update the Analysis and get back to you. Thanks!

Edit Update: Analysis reporting just what I need, either individual or multiple results. Thank!
image

2 Likes