在TCL脚本: 我有一个文件我知道如何寻找一个字符串,但如何获得行号时字符串是found.please回答我,如果有可能如何从tcl中的文件获取两个字符串之间的数据?
或
set fd [open test.txt r]
while {![eof $fd]} {
set buffer [read $fd]
}
set lines [split $buffer "\n"]
if {[regexp "S1 Application Protocol" $lines]} {
puts "string found"
} else {puts "not found"}
#puts $lines
#set i 0
#while {[regexp -start 0 "S1 Application Protocol" $line``s]==0} {incr i
#puts $i
#}
#puts [llength $lines]
#puts [lsearch -exact $buffer S1]
#puts [lrange $lines 261 320]
在上面的程序中,我得到的输出作为字符串找到.if我会给这个字符串以外的字符串我没有找到字符串。
你尝试过这么远吗?如果你告诉我们你做了什么,你会得到更好的回应。 – Jackson 2013-03-08 11:45:10
我试图用regexp command.i能够找到字符串,但如何从文件中找到行号? – user2147935 2013-03-08 11:50:05