All Forums >> [Scripting] >> WSH & Client Side VBScript >> Reading in the last couple lines of a file, and regexp'ing? Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
What I'd like to do is read in the last 10 lines and put the minutes field into an array to see if the errors are happening regularly. This file is hundreds of lines long.
I'm more familiar with Unix, so I'd do something like "tail -n10", read each of the lines into an array and then regexp the minutes field. Is there anything similar that can be done using VBscript?
I've got somewhat of a solution on pulling the last x lines, but it is not working if I try to "tail" more lines then is in the file. So, if I set lngTail to 10, but there are only 5 lines in the file it crashes out.
VBScript may not be as fast as Perl (or C), but this code:
output:
creates, tails, and collects all Errors in a 500000 lines / 25 MB file in under a minute. So I wouldn't bother with tailing, just use .ReadLine and a Dictionary.