在 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]
在上面的程序中,我将输出作为找到的字符串。如果我将在此文件中提供字符串以外的字符串,我将得到未找到的字符串。