Hi Team
I am newbie to VBscript and looking for an help. There are many log files in a folder. I want to search a string string1 and get its id loaded to a variable var1. Then search another string2 within the same id var1 if it is found some data in the log within the same var1 id need to be exported to an excel.
Please let me know whether i can achieve this in VBscript. Any helps and suggestions are welcome
the log file contains like below line multiple lines.
Line 8122: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | starts
Line 8123: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| DQLN=EQUAL_QUAL_QUEUE_GOHEAD_IT
Line 8124: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| INDX=1
Line 8125: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| DQLN=Another_id
Line 8126: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| Name=QID|Inputs=[accNumber=12457845,oon=6842703020]|Outputid=00a4028a87c4473f,amid=2353.6,TransactionTime=125ms
.........
Line 8160: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | ends
String1 is: QUAL_QUEUE_GOHEAD_IT
Var1 is: JEZHckpTehtA-ADSW4T14T5
string2 is: Another_id
need to get details of accNumber=12457845,oon=6842703020,Outputid=00a4028a87c4473f,amid=2353.6 values to excel sheet.
I have the below code for it just started working on it,
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Users\shambu\Desktop\otq"
Set objFolder = objFSO.GetFolder(objStartFolder)
Dim varid
For Each objFile in objFolder.Files
set oStream = objFile.OpenAsTextStream(1)
If not oStream.AtEndOfStream Then
contents = oStream.ReadAll
End If
oStream.Close
Set re = New RegExp
re.Pattern = "INFO \| ([^\|]*) \|.*QUAL_QUEUE_GOHEAD_IT"
re.Global = True
Set matches = re.Execute(contents)
For Each match In Matches
varid = match.SubMatches(0)
ProcessMatch objFile.Path, varid
Next
Next
sub ProcessMatch(path, id)
Msgbox "Match " & id & " found in " & path
end sub
I am newbie to VBscript and looking for an help. There are many log files in a folder. I want to search a string string1 and get its id loaded to a variable var1. Then search another string2 within the same id var1 if it is found some data in the log within the same var1 id need to be exported to an excel.
Please let me know whether i can achieve this in VBscript. Any helps and suggestions are welcome
the log file contains like below line multiple lines.
Line 8122: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | starts
Line 8123: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| DQLN=EQUAL_QUAL_QUEUE_GOHEAD_IT
Line 8124: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| INDX=1
Line 8125: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| DQLN=Another_id
Line 8126: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | EVNT=SWIdmst|DQLN=YN| Name=QID|Inputs=[accNumber=12457845,oon=6842703020]|Outputid=00a4028a87c4473f,amid=2353.6,TransactionTime=125ms
.........
Line 8160: Feb 01 19:44:40.961 | INFO | JEZHckpTehtA-ADSW4T14T5 | PROD | 10.86.99.108 | Feb 01 2016 19:44:29.595 | ends
String1 is: QUAL_QUEUE_GOHEAD_IT
Var1 is: JEZHckpTehtA-ADSW4T14T5
string2 is: Another_id
need to get details of accNumber=12457845,oon=6842703020,Outputid=00a4028a87c4473f,amid=2353.6 values to excel sheet.
I have the below code for it just started working on it,
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Users\shambu\Desktop\otq"
Set objFolder = objFSO.GetFolder(objStartFolder)
Dim varid
For Each objFile in objFolder.Files
set oStream = objFile.OpenAsTextStream(1)
If not oStream.AtEndOfStream Then
contents = oStream.ReadAll
End If
oStream.Close
Set re = New RegExp
re.Pattern = "INFO \| ([^\|]*) \|.*QUAL_QUEUE_GOHEAD_IT"
re.Global = True
Set matches = re.Execute(contents)
For Each match In Matches
varid = match.SubMatches(0)
ProcessMatch objFile.Path, varid
Next
Next
sub ProcessMatch(path, id)
Msgbox "Match " & id & " found in " & path
end sub