在大文件中连续搜索模式的新术语的好方法是什么?

What is a good approach for continuous searching for a fresh term of a pattern in a large file?

AUT 为特定功能创建日志 运行 并将日志附加到中央文件中。 在此文件中搜索的行是:

LatestTimeStamp>MyFunction   SomeStep timeLapsed  SOME_TIME_VALUE

每次 AUT 生成日志时,都会生成多个与上述类似模式的新日志,并且需要提取这些新日志。

我使用的简单方法是:

class结构

itcl::class clsLogs {
    variable _oldTimeStamp ""
    variable _logRec
    variable _runCtr 0
    method _extractInfoForRun {runType} {
        #read log
        catch {close $fp}
        set log [read [set fp [open [file join [file normalize $env(APPDATA)] Logs Action.log]]]]
        
        #garbage everything before old time stamp and collect all fresh log
        if {[info exists _oldTimeStamp] && $_oldTimeStamp!=""} {
            regsub [subst -nobackslashes -nocommands {.*$_oldTimeStamp[^\n]*\n}] [set freshLog $log] "" freshLog
        }

        #increment run counter for this run
        incr _runCtr
        
        #get all fresh entry lines for reporting timelapsed for different steps of MyFunction in this run
        set freshEntries [regexp -inline -all [subst -nocommands -nobackslashes {[^\n]*MyFunction[^\n]*timeLapsed[^\n]*}] $freshLog]
        
        #iterate and collect time lapsed info for each step of MyFunction for this run
        foreach ent $freshEntries { 
            regexp {(.*?)>.*>>MyFunction\s+(.*)\s+timeLapsed\s+(.*)$} $ent -> timeStamp runStep lapsedTime ;
            puts ************runTyp>$runTyp***********\n\t$ent\n\ttimeStamp->$timeStamp\nlapsedTime->$lapsedTime
            set _logRec(MyFunction_Run-$_runCtr:$runStep,lapsedTime) $lapsedTime
        }           
        
        #reset old time stamp variable for next run
        set _oldTimeStamp $timeStamp
    }
}

但是这个文件可能很大,将所有内容存储在一个读取输出变量中可能会导致溢出:

set log [read [set fp [open [file join [file normalize $env(APPDATA)] Logs Action.log]]]]

是否有可能使用组合来获取文件指针的当前位置并使用它偏移到上一个光标位置,然后每次都从该位置开始读取? 相同的 Tcl 命令选项是什么?

这样做:

seek [set fp [open $file]] $_fOffset
set txt [read $fp]
set _fOffset [tell $fp]

在上下文中:

::itcl::class clsLogs {
    private {
        variable _fOffset 0     
    }
    public {
        method _fFreshRead {file args} {
            set options(-resetOffSet) false
            array set options $args         
            if {$options(-resetOffSet)} {
                set _fOffset 0
            }
            seek [set fp [open $file]] $_fOffset            
            set txt [read $fp]
            set _fOffset [tell $fp]
            close $fp
            return $txt
        }
    }
}