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