使用 tcl 脚本将数据提取到不同的文件

Extract data to different file using tcl script

我正在尝试将每个检查提取到每个新文件中。

提取数据文件的内容(report.txt)

 Information: Checking 'data_check_multiple_clock'.
 Information: Checking 'data_check_no_clock'.  
 Information: Checking 'no_driving_cell'.
 Warning: There are 5 ports with parasitics but with no driving cell.

 Ports
 ------------------------------------------------------------
 atb0_uib
 atb1_uib
 a[0]
 b[1]
 b[2]

 Information: Checking 'cell'.

我想要的示例输出:

在data_check_multiple_clock.txt的内容中, 该文件是空的,因为没有写入错误。

同样适用于 data_check_no_clock.txt 和 cell.txt

然而,no_driving_cell.txt内容如下:

atb0_uib
atb1_uib
a[0]
b[1]
b[2]

知道怎么做吗? 以下是在空错误时出错的编码,其中所有文件都在 no_driving_ 单元格中发现相同的错误。

        set var "Information: Checking '[lindex $argv $i]'"
        set fi [open "$line" r]
        set fo [open "check_[lindex $argv $i].csv" a]

        # Extract data to output file
        while {[gets $fi line1] !=-1} {
            if {[regexp "$var" $line1]} {
                puts "check_timing_info: Found $line1"
                puts $fo $line1
                puts $fo $line
                set flag 1
            }
            if {$flag eq 1} {
                if {[regexp "$var1" $line1]} {
                    set flag 2
                } elseif {[regexp "^Error" $line1]} {
                    set flag 2
                }   
            } 
            if {$flag eq 2} {
                if {[regexp "Information: Checking" $line1]} {
                    set flag 0
                } elseif {[regexp "$var1" $line1]} {

                } else {    
                #   puts $line1
                    puts $fo $line1
                }
            }

        }
        close $fo
    }
    } else {

    } 
     }
}

老实说,我不太清楚你想在这里做什么,但这样的事情可能行得通吗?

set fi [open report.txt]

while {[gets $fi line] >= 0} {
    switch -glob $line {
        Information:* {
            set filename [lindex [regexp -inline {'(.*)'\.$} $line] 1]
        }
        --* {
            puts $filename
            while {[gets $fi line] >= 0} {
                if {[string is space $line]} {
                    break
                }
                puts $line
            }
        }
    }
}

它产生输出(我正在输出到标准输出,因为这使实验更容易):

no_driving_cell
atb0_uib
atb1_uib
a[0]
b[1]
b[2]