0

我需要使用我尝试遵循的 tcl 脚本从文件的两个连续行中获取两个不同的字符串,但它不起作用。所以在下面我需要打印字符串“Clock”和“b0”。我可以打印时钟。但我需要两个“时钟”“b0”

set f [eval exec "cat src.txt"]
set linenumber 0

while {[gets $f line] >= 0} {
    incr linenumber
    if {[string match "Clock" $line] >= 0 } {
        # ignore by just going straight to the next loop iteration
        while {[gets $f line] >= 0} {
            incr linenumber
            if { [string match "b0" $line"]} {
                close $out
                puts "final $line"
            }      
            puts "\n$line"
            continue
        }
    }
}
close $f
4

1 回答 1

0

这是你想要的吗?

set f [open "src.txt" r]; # opening file

while {![eof $f] >= 0} {
    set line [gets $f]; # reading line from file
    if {[string match "*Clock*" $line]} {
        ; # if Clock found
        puts $line
        set line [gets $f]; # reading next line from file
        if { [string match "*b0*" $line]} {
            ; # if b0 found
            puts "final $line"
        }
    } 
}
close $f
于 2013-09-19T07:04:45.220 回答