TCL script help

Hi All ,

I am having a file as stated below

File 1

chain = chan6   group = grp0  input = '/pad_pc10'  output = '/pad_pb7'  length = 9900
chain = chan2   group = grp0  input = '/pad_pa4'  output = '/pad_pb12'  length = 10000
chain = chan7   group = grp0  input = '/pad_pb2'  output = '/pad_pb15'  length = 9754
chain = chan3   group = grp0  input = '/pad_pa0'  output = '/pad_pb13'  length = 10000
chain = chan4   group = grp0  input = '/pad_pb3'  output = '/pad_pb10'  length = 10000
chain = chan0   group = grp0  input = '/pad_pc0'  output = '/pad_pb14'  length = 9917
chain = chan5   group = grp0  input = '/pad_pb9'  output = '/pad_pb11'  length = 9994
chain = chan1   group = grp0  input = '/pad_pc1'  output = '/pad_pa1'  length = 10000
chain = CWG   group = grp0  input = '/pad_pb0'  output = '/pad_pb4'  length = 97

I want to write a tcl script which will match the regexp output and then print only the output variables

OUTPUT file

'/pad_pc10'
'/pad_pa4'
'/pad_pb2'
'/pad_pa0'
'/pad_pb3'
'/pad_pc0'
'/pad_pb9'
'/pad_pc1'
'/pad_pb0'

I have tried to write below script but its not working
Pleas help me out

set fd [open "report" r]
while {[gets $fd line] >= 0} {
    if {[regexp "output" $line match match1]} {
        if {$match1 == 1} {
            puts $line
        }
    }
}

You never tell Tcl, what parts of the string you are interested in. How can Tcl the conclude, that you want that specific part of your line? Tcl is neither magic nor mind-reading.

In your case, the variable match will contain output (since this is what your regexp matches), and match1 will be empty.

Change the matching command to

regexp "output.*?('.*?')" $line match match1

and it will work for your input data.

Of course it still would break if you have a line, for instance, containing input = 'xxxoutputyyy', but this is a different issue.