Hi again all - here’s another analysis that I’m struggling with a little.
Looking at a config file, looking for a specific stanza of the file, then looking for a option that has specific value set.
For example:
following text of first “stanza identifier {” of “/path/filename.conf” whose (exists (line of it) whose (it as lowercase contains “keyword”) whose (it as lowercase contains “optionvalueword”))
Hmmm, looking through that just a bit more (and thinking it through), that would seem to get me back the property and show me what the setting is, which probably works well for my needs, though I’m wondering about testing that value for specific expected result?
I would guess that I could do some sort of contains or starts with check against the returned value, no?
That’s a bit trickier (the “key” and “section” inspectors are built to match .INI file processing) but it’s possible still with the plain-text “lines of file” family.
Are there any cases where you need to deal with embedded {} characters, or are there only curly brackets used in defining stanzas?
Hi Jason, for my purposes, I think I would only find the curly braces defining sections of the .conf file that I’m looking through for values.
I had tried to use something like this:
following text of first "stanza header I would be looking for {" of "/path/file.conf" whose (exists (line of it) whose (it as lowercase contains "key_name") whose (it as lowercase contains "value_i_want_to_look_for"))
but that was not working for me (probably miss placed an “it” again )
It’s a pretty complicated case you have. In order to look at “following text of” you need a single string - but if you are reading the lines of a file, you are only looking for “following text” within the same line.
Here is one potential way, probably not the best. It’s quick-and-dirty, no error handling for things like a missing stanza, missing value, or weird spacing, but if your files are all formed predictably it may be helpful. I start by concatenating all of the lines of the file together, then look for the stanza of interest, then break out just that stanza into the original line contents.
q: lines of file "c:\temp\test-stanza.txt"
A: stanza {
A: ## comment or other text...
A: key1 = stanza1-value,value2,value3
A: }
A:
A: stanza-two {
A: ## comment
A: key1=stanza-two-value
A: }
T: 0.440 ms
I: plural file line
q: concatenation "|" of lines of file "c:\temp\test-stanza.txt"
A: stanza {| ## comment or other text...| key1 = stanza1-value,value2,value3|}||stanza-two {| ## comment| key1=stanza-two-value|}
T: 0.501 ms
I: singular string
q: preceding text of first "}" of following text of first "stanza {" of concatenation "|" of lines of file "c:\temp\test-stanza.txt"
A: | ## comment or other text...| key1 = stanza1-value,value2,value3|
T: 0.526 ms
I: singular substring
q: substrings separated by "|" whose (it as trimmed string starts with "key1") of preceding text of first "}" of following text of first "stanza {" of concatenation "|" of lines of file "c:\temp\test-stanza.txt"
A: key1 = stanza1-value,value2,value3
T: 0.580 ms
I: plural substring
q: following texts of firsts "=" of substrings separated by "|" whose (it as trimmed string starts with "key1") of preceding text of first "}" of following text of first "stanza {" of concatenation "|" of lines of file "c:\temp\test-stanza.txt"
A: stanza1-value,value2,value3
T: 0.604 ms
I: plural substring
Thanks Jason, I think you’ve nailed it for me.
I don’t need that much error checking and such, so either of those last two examples put me where I need to be (I think).
I like the one that shows the key1 = better, but either of them should work. (The output for that would look a little better I think)
That seems to be doing exactly what I need though as it makes it easy to confirm that the key is set correctly.
Got exactly what I needed now. It shows me the key value for quick and easy inspection. Awesome, thanks again @JasonWalker and others for the assistance. Much appreciated!