TCL文件查找拆分

来源:互联网 发布:淘宝买貂皮 编辑:程序博客网 时间:2024/04/29 13:44


TCL文件查找拆分

我现在有一个 .res 的文件,这个文件中包括以下两行测试结果:

        rdly=  3.4405E-10  targ=  2.0084E-07   trig=  2.0050E-07
        fdly=  3.1211E-10  targ=  1.0081E-07   trig=  1.0050E-07

现在我想写一个Tcl文件拥有功能如下:

1. 读这个 .res 文件并寻找到上述的那两行信息(这两行所在的行数未知)。
2. 生成一个 ASCII 的 .txt 文件,文件内容应当如下:
        Rise Delay is [rdly 的测试结果,在这里应当是3.4405E-10] 
        Fall Delay is [fdly 的测试结果,3.1211E-10]

set srcfile myres.resset dstfile dtest.txtif {[catch {open $srcfile r} res]} { puts "Failed to open the source file: $srcfile; $res" return 0}set hSrc $resif {[catch {open $dstfile w+} res]} { puts "Failed to open the destination file: $dstfile; $res" return 0}set hDst $resforeach line [split [read $hSrc] \n] { if {[regexp {rdly=(.*)targ=(.*)trig=(.*)} $line match sub1]} {  puts $hDst "Rise Delay is $sub1" } if {[regexp {fdly=(.*)targ=(.*)trig=(.*)} $line match sub1]} {  puts $hDst "Fall Delay is $sub1" }}close $hSrcclose $hDst


0 0
原创粉丝点击