I tried to solve problem with regex to print parent and its child section. I got parent lines but could not print its child lines. please assist if you are good with powershell regex.
PS D:\> Get-Content .\config.txt
object-group network APP_GROUP
network-object host 10.10.20.1
network-object host 10.10.20.2
network-object host 10.10.20.3
object-group network WEB_GROUP
network-object host 10.10.30.1
network-object host 10.10.30.2
network-object host 10.10.30.3
PS D:\> Get-Content .\config.txt | Select-String "(^object-group\s+\w+\s+\w+.)"
object-group network APP_GROUP
object-group network WEB_GROUP
PS D:\>
I'm not able to add new child line begins with "network-object" at the end of regex as below which doesn't work. also the number of child lines are dynamic.
Get-Content .\config.txt | Select-String "(^object-group\s+\w+\s+\w+.)(^\n\snetwork-object*)"