ajtsystems
IS-IT--Management
hi there,
My script below searches through an error log for a string which is set in the script as a regular expression. When it finds the string(s) they are copied to another file.
searchstring = "Somestring"
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "^25-09-2007 Somestring"
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", 1)
Set objFile1 = objFSO.OpenTextFile("C:\Scripts\results.txt", 2)
'check through text file and create 1d array
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
'Read through array from last line to 1st line
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
hello = arrFileLines(l)
'Check for regular expression and write to file if exists
Set colMatches = objRegEx.Execute(hello)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
Wscript.Echo (hello)
Next
objFile1.writeline (hello)
End If
next
objFile1.Close
What I need to do is compare the strings copied to see whch has the latest date stamp. Just to fill you in, the file which is searched is a log file and has entries in such as this
11-06-2010 Error 612 occured
12-06-2010 Error 612 occured
I need to differentiate between strings probably using the instr function to see which occurence is the later date. If this is too complicated is there something in the array where I can do this without creating a new output file with my results?
Thanks
James
My script below searches through an error log for a string which is set in the script as a regular expression. When it finds the string(s) they are copied to another file.
searchstring = "Somestring"
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "^25-09-2007 Somestring"
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", 1)
Set objFile1 = objFSO.OpenTextFile("C:\Scripts\results.txt", 2)
'check through text file and create 1d array
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
'Read through array from last line to 1st line
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
hello = arrFileLines(l)
'Check for regular expression and write to file if exists
Set colMatches = objRegEx.Execute(hello)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
Wscript.Echo (hello)
Next
objFile1.writeline (hello)
End If
next
objFile1.Close
What I need to do is compare the strings copied to see whch has the latest date stamp. Just to fill you in, the file which is searched is a log file and has entries in such as this
11-06-2010 Error 612 occured
12-06-2010 Error 612 occured
I need to differentiate between strings probably using the instr function to see which occurence is the later date. If this is too complicated is there something in the array where I can do this without creating a new output file with my results?
Thanks
James