Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Reading in the last couple lines of a file, and regexp'ing?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59596
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Reading in the last couple lines of a file, and regexp'... - 4/28/2008 8:46:21 AM   
  elinenbe

 

Posts: 10
Score: 0
Joined: 4/24/2008
Status: offline
I have a file that looks like this:

04/26/08:12:51:17 - c:\log\log.txt - Error 481295
.... (a bunch cou out here)
04/27/08:12:46:03 - c:\log\log.txt - Error 481295
04/27/08:12:46:26 - c:\log\log.txt - Error 234245
04/27/08:13:04:53 - c:\log\log.txt - Error 481295
04/27/08:13:22:30 - c:\log\log.txt - Error 234560
04/27/08:13:22:54 - c:\log\log.txt - Error 000342
04/27/08:14:23:27 - c:\log\log.txt - Error 000012
04/27/08:15:58:40 - c:\log\log.txt - Error 000524
04/27/08:18:43:05 - c:\log\log.txt - Error 000034
04/27/08:20:58:28 - c:\log\log.txt - Error 000452
04/27/08:20:58:50 - c:\log\log.txt - Error 000053
04/27/08:20:59:14 - c:\log\log.txt - Error 000167

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?

Thanks,
Eric
Eric
 
 
Post #: 1
 
 RE: Reading in the last couple lines of a file, and reg... - 4/28/2008 9:04:01 AM   
  elinenbe

 

Posts: 10
Score: 0
Joined: 4/24/2008
Status: offline
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.


      

(in reply to elinenbe)
 
 
Post #: 2
 
 RE: Reading in the last couple lines of a file, and reg... - 4/28/2008 10:07:57 AM   
  ehvbs

 

Posts: 2025
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi elinenbe,

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.

Good luck!

ehvbs

(in reply to elinenbe)
 
 
Post #: 3
 
 RE: Reading in the last couple lines of a file, and reg... - 4/29/2008 2:50:52 AM   
  elinenbe

 

Posts: 10
Score: 0
Joined: 4/24/2008
Status: offline
When I try to use this piece of code I get:

tail.vbs(11, 6) Microsoft VBScript runtime error: Type mismatch: 'IRandR'

Thanks,
Eric

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Reading in the last couple lines of a file, and reg... - 4/29/2008 4:26:12 AM   
  ehvbs

 

Posts: 2025
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi elinenbe,

sorry about that; I forgot to include this function:


      

Ashamed

ehvbs

(in reply to elinenbe)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Reading in the last couple lines of a file, and regexp'ing? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts