本帖最后由 ipmitool 于 2017-3-8 18:51 编辑
如何查找 Txt 關鍵字並且列出關鍵字那一行?
Found (.*) suspect error
列出(.*) 及 當行的字串
#include <FileConstants.au3>
#include <File.au3>
FileDelete("AnalyzeWCSLog.txt")
$CycleTime=InputBox ("Input Cycle Time" , "Please input Cycle Time " & @CRLF _
& @CRLF _
&"" ,"","")
if $CycleTime="" then Exit
for $i=1 to $CycleTime
;######################################################################################################################
;get all folder names
$FileList = _FileListToArray(@ScriptDir&"\cycle"&$i, "Check-WcsError*", 2)
$fFolder = _ArrayToString($FileList)
$fFolder = StringTrimLeft($fFolder, 2)
;MsgBox(0,"111",$fFolder)
$Openlog = FileOpen(@ScriptDir&"\cycle"&$i&"\Check-WcsError-Summary.log")
$filelog = @ScriptDir&"\cycle"&$i&"\Post-Test"&$fFolder&"\Check-WcsError-Summary.log"
$OpenlogReadLine = FileReadLine($Openlog,6)
;MsgBox(0,"111",$OpenlogReadLine)
;######################################################################################################################
$filelog = @ScriptDir&"\cycle"&$i&"\Check-WcsError-Summary.log"
Local $scriptfilelog = FileOpen($filelog)
$line = FileRead($scriptfilelog)
$False = StringRegExp($line, "Found (.*) suspect error", 3)
for $k = 0 to UBound($False) - 1
$FalseK001=$False[$k]
If $FalseK001="NO" then
Else
$filelogsss = FileOpen("AnalyzeWCSLog.txt", 1)
FileWriteLine($filelogsss, "Cycle Time: "&$i&", Error: "&$FalseK001)
FileWriteLine($filelogsss, "")
FileClose($filelogsss)
EndIf
Next
Next
if FileExists(@ScriptDir&"\AnalyzeWCSLog.txt") Then
MsgBox(0,"Message","Please check AnalyzeWCSLog.txt")
Else
MsgBox(0,"Message","PASS! No Error Logs found!")
EndIf
|