我有一個文件測試1:如何標記文件中的行?
Par1
Par2
Par3
Par4
Par1
Par5
Par5
我做了這個的Tcl對其進行過濾:
set thefile [open test1 "r"]
set is_Par1 0
set is_Par3 0
while {![eof $thefile]} {
set line [gets $thefile]
if { [regexp {Par1} $line] } {
set thefile2 [open test2 "w"]
set is_Par1 1
}
if { [regexp {Par3} $line] } {
set is_Par3 1
set is_Par1 0
}
if { $is_Par1 && !$is_Par3 } {
puts $thefile2 $line
}
if { [regexp {Par4} $line] } {
set is_Par3 0
close $thefile2
}
}
close $thefile
讓我們假設該文件和圖案都比較複雜(我已經簡化它)
我有這樣的結果:
Par1
Par5
Par5
但我想有這樣的結果:
Par1
Par2
我不明白是我的錯!
好的,很好的解決方案謝謝 – heyhey 2012-07-26 14:27:01
+1對於'eof'提示 – kostix 2012-07-27 08:06:15