[已解决]如何查找Txt關鍵字並且列出關鍵字那一行?
本帖最后由 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
回复 1# ipmitool
好象加个判断就可以
$FalseK001 = $False[$k]
If $CycleTime=$FalseK001 Then 回复 2# chzj589
可是...$CycleTime是資料夾的數字耶... 这种借助命令行的 findstr 处理相当便捷
findstr /c:"test" c:\1.txt
得到文件中 c:\1.txt 所有含字符串 test 的行 回复 3# ipmitool
你可以调试一下
$CycleTime是資料夾的數字
$FalseK001是读取的數字 这种借助命令行的 findstr 处理相当便捷
findstr /c:"test" c:\1.txt
得到文件中 c:\1.txt 所有含字符串...
zghwelcome 发表于 2017-3-8 11:30 http://www.autoitx.com/images/common/back.gif
謝謝兩位大哥大大~ 謝謝兩位大哥大大~
ipmitool 发表于 2017-3-8 18:50 http://www.autoitx.com/images/common/back.gif
回复 8# chzj589
帥氣喔, 可不可以開放原碼, 之後用的上您的運用~ 回复 9# ipmitool
己发站内短信,请查收!
页:
[1]