I have to read the 5th last line from log file through a vb script. Can somebody please guide me how to do it?
I am using following code which only reads the last line and echo last line and line count, need to enhance it.
Dim fh, fso, sLastLine, lineCount
Set fso = CreateObject("Scripting.FileSystemObject")
Set fh = fso.OpenTextFile( "E:\Coding\VB\demo.txt" )
sLastLine = ""
lineCount = 0
Do Until fh.AtEndOfStream
lineCount = lineCount + 1
sLastLine = fh.ReadLine()
Loop
fh.Close
WScript.Echo sLastLine
WScript.Echo lineCount
Content for demo.txt is as follows:
zcZcxZCsdfdfsfd
aaaaa
bbbb
cccc
dddd
eeee
In the end there are 4 blank lines and i have to read the "eeee" here.