从日志文件中提取特定数据

时间:2016-06-03 05:06:20

标签: vbscript

我有一个日志文件,我需要从中提取所有内容" Ath响应如下:"直到"结束了反应",我对vbs相当新,可以请某人建议实现此目的。

示例日志: -

background-size: contain;

1 个答案:

答案 0 :(得分:0)

试试这段代码。它读入名为 myLog.log 的文件,并输出名为 result.log 的文件。

option explicit
dim fso, myLog, oneLine, insideBlock, textBlock, markerFound
set fso = CreateObject("Scripting.FileSystemObject")
set myLog = fso.OpenTextFile("MyLog.Log")
insideBlock = false
markerFound = false
textBlock = ""
do while not myLog.AtEndOfStream
    oneLine = myLog.readLine
    markerFound = instr(lcase(oneLine),"ath response")>0
    if insideBlock then
      if not markerFound then
        textBlock = textBlock & oneLine & vbcrlf
      else
        exit do
      end if
    else
      insideBlock = markerFound
    end if
Loop
myLog.Close
set myLog = fso.CreateTextFile("result.log")
myLog.Write(textBlock)
myLog.Close