set file [open nvram:/startup-config] set section 0 set ok 0 while {[gets $file line] >= 0} { switch -regexp -- $line { {^\w} { if {[regexp [lindex $argv 0] $line]} { set section $line } } {^\s} { lappend subcommands $line if {[regexp [lindex $argv 1] $line]} { set ok 1 } } {^!$} { if {$section != 0} { if {$ok == 1} { puts $section foreach subcommand $subcommands { puts $subcommand } } } set subcommands 0 unset subcommands set section 0 set ok 0 } } } close $file