0

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*)"
RAM
  • 11
  • 1
  • *sigh* already answered here: https://stackoverflow.com/questions/50654464/ – Bill_Stewart Jun 05 '18 at 15:49
  • Thanks all I solved and updated in my other post [other post](https://stackoverflow.com/questions/50654464/read-section-of-lines-from-cisco-ios-configuration-loaded-as-text-file-in-powers) – RAM Jun 08 '18 at 10:19

0 Answers0