I want to take time-stamp values from a log file which is in text format in my local machine and save these into an Excel file, using VB Scripting.
My log file format is:-
14.000.00.10 - - [07/Mar/2015:16:06:51 -0800] "GET /twiki/bin/rdiff/TWiki/NewUserTemplate?rev1=1.3&rev2=1.2 HTTP/1.1" 200 4523 14.000.00.10 - - [07/Mar/2015:16:10:02 -0800] "GET /mailman/listinfo/hsdivision HTTP/1.1" 200 6291 14.000.00.10 - - [07/Mar/2015:16:11:58 -0800] "GET /twiki/bin/view/TWiki/WikiSyntax HTTP/1.1" 200 7352 14.000.00.10 - - [07/Mar/2015:16:20:55 -0800] "GET /twiki/bin/view/Main/DCCAndPostFix HTTP/1.1" 200 5253 14.000.00.10 - - [07/Mar/2015:16:23:12 -0800] "GET /twiki/bin/oops/TWiki/AppendixFileSystem?template=oopsmore¶m1=1.12¶m2=1.12 HTTP/1.1"
By taking an ID value which is coming repeatedly in multiple lines, how can I save my timestamp e.g. [07/Mar/2015:16:23:12]
from log .txt file to Excel file?
I tried to code this:
Set xl = CreateObject("Excel.Application")
xl.Visible = True
Set wb = xl.Workbooks.Add
Set ws = wb.Sheets(1)
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("E:\access_log.txt")
strContents = objFile.ReadAll
objFile.Close
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = "mailman"
Set colMatches = objRegEx.Execute(strContents)
For Each Match in colMatches
strReturnStr = "Match found at position "
strReturnStr = strReturnStr & match.FirstIndex & ". Match Value is '"
StrReturnStr = strReturnStr & match.value & "'." & "<BR>" & VBCrLf
WScript.Echo(strReturnStr)
Next
wb.SaveAs "E:\access_og.csv", -4143, , , , False
wb.Close
xl.Quit
While running with cscript name.vbs on cmd prompt it is showing line numbers where string found, and after that .csv file is opening with error "the file format and extension of 'access_og.csv' don't match. the file could be corrupted and unsafe."
Still problem not solved :(