#########################################################################
#函数名称:readtxt
#参 数:fname-------需要打开的文件名
# lookstr-------待查找的字符串
#返 回 值:flag------------在fname中查到lookstr的次数
#########################################################################
proc readtxt {fname lookstr } {
#加载Expect包
package require Expect
#指定当前工作目录
set dir [ file dirname [info script]]
if {[string equal $dir "."]} {
set dir [pwd]
}
#找到的标志
set flag 0
#set data_path [file join $dir $fname]
# set data [open $data_path r]
if [catch {open [file join $dir $fname] r} fd] {
puts "no $fname $fd"
} else {
set rowid 0
while {[eof $fd] !=1} {
incr rowid
gets $fd line
#puts "读 $rowid $line"
##########################################
set sense [string first $lookstr $line]
#puts $sense
############################################
if { $sense != -1 } {
#每找到一次标志位+1
incr flag
#puts "判断结果为:$flag"
}
}
close $fd
}
return $flag
}
#函数名称:readtxt
#参 数:fname-------需要打开的文件名
# lookstr-------待查找的字符串
#返 回 值:flag------------在fname中查到lookstr的次数
#########################################################################
proc readtxt {fname lookstr } {
#加载Expect包
package require Expect
#指定当前工作目录
set dir [ file dirname [info script]]
if {[string equal $dir "."]} {
set dir [pwd]
}
#找到的标志
set flag 0
#set data_path [file join $dir $fname]
# set data [open $data_path r]
if [catch {open [file join $dir $fname] r} fd] {
puts "no $fname $fd"
} else {
set rowid 0
while {[eof $fd] !=1} {
incr rowid
gets $fd line
#puts "读 $rowid $line"
##########################################
set sense [string first $lookstr $line]
#puts $sense
############################################
if { $sense != -1 } {
#每找到一次标志位+1
incr flag
#puts "判断结果为:$flag"
}
}
close $fd
}
return $flag
}