Lines of file between lines

We have a text file. Content like the following:
[daemon]
InitialSetupEnable=False
Uncoment the line below to force the login screen to use Xorg
WaylandEnable=false

[security]

[xdmcp]

[chooser]

[debug]
Uncomment the line below to turn on debugging
Enable=true

How to use relevance to list only [daemon] section lines? like:
[daemon]
InitialSetupEnable=False
Uncoment the line below to force the login screen to use Xorg
WaylandEnable=false

Thanks for the help.

If this is a .ini-formatted file you might try the ‘section of file’ and ‘key of section of file’ inspectors described at https://developer.bigfix.com/relevance/reference/file-section.html

You could also try ‘variables of file’ https://developer.bigfix.com/relevance/reference/file.html#variable-of-file-string

The ‘key of section’ inspectors requires that you know the section and key names, there is not an iterator to loop through all of them. If you don’t know all of the expected key names, you can use ‘variables of file’ to loop through them, as the variable names are prefixed with the section name

q: key "InitialSetupEnable" of section "daemon" of file "c:\temp\test.ini"
A: False
I: singular string

q: key "WaylandEnable" of section "daemon" of file "c:\temp\test.ini"
A: false
I: singular string

q: variables of file "c:\temp\test.ini"
A: [daemon].InitialSetupEnable=False
A: [daemon].WaylandEnable=false
A: [debug].Enable=true
I: plural string


q: variables whose (it starts with "[daemon]") of file "c:\temp\test.ini"
A: [daemon].InitialSetupEnable=False
A: [daemon].WaylandEnable=false
I: plural string

q: following texts of firsts "[daemon]." of variables whose (it starts with "[daemon]") of file "c:\temp\test.ini"
A: InitialSetupEnable=False
A: WaylandEnable=false
I: plural substring
1 Like

OK We will try it.
And if it is only a text file for it?
How could we lines the specific lines of it?

Thanks for the help.

Might not be the best way but what I would do is create a tuple and run through the file 3 times (first to get the line number of the starting point, second to get the line number of end point and 3rd to get the output you are after). Not very well designed but in the absence of formatting…

q: lines of file "c:\temp\test.txt"
A: [daemon]
A: InitialSetupEnable=False
A: Uncoment the line below to force the login screen to use Xorg
A: WaylandEnable=false
A: 
A: [security]
A: 
A: [xdmcp]
A: 
A: [chooser]
A: 
A: [debug]
A: Uncomment the line below to turn on debugging
A: Enable=true
T: 1.713 ms
I: plural file line

q: (item 2 of it) of (/* line number of starting point */ line number of line starting with "[daemon]" of it, /* line number of end point */ minimum of line numbers of lines whose (it = "") of it, /* all lines to be filtered by whose statement */ lines of it) whose (/* filtering the lines based on start & end points */ line number of item 2 of it > item 0 of it and line number of item 2 of it < item 1 of it) of file "c:\temp\test.txt"
A: InitialSetupEnable=False
A: Uncoment the line below to force the login screen to use Xorg
A: WaylandEnable=false
T: 1.204 ms
I: plural file line
3 Likes

@ageorgiev has a good working solution.

This is very similar to a relevance challenge from a few years ago, several working solutions are posted here…none of them easy.

Relevance Challenge December 2019 BONUS: Parsing Paragraphs (answer provided)

2 Likes