Solved

Extract data from a text file under certain conditions....

Posted on 2004-09-17
11
153 Views
Last Modified: 2010-05-02
Hi all,
I want to extract data from a McAfee logfile, but as I am a newbie in programming vbs I don't know which code I need in the vbs script.
Every day a full system scan is performed and and the results are placed in a logfile on every server. I need to extract the data from a specific date from this logfile.
The text given in the logfiles are in this format:
"9/17/2004      1:30 AM      Scan Started  NT AUTHORITY\SYSTEM      Scan All Fixed Disks"

So I need to extract all lines from the logfile containing the current date in the given format 9/17/2004.
Does anybody know how to do this?

0
Comment
Question by:Schurink
11 Comments
 
LVL 7

Expert Comment

by:_agj_
Comment Utility
use dos to do that:

find "9/17/2004" mcafee.log

will list all lines containign this date
0
 

Expert Comment

by:itmastero
Comment Utility
You can use fso or the open command in vb to open the logfile and then start reading the file. You can also use the mid function or instr function to check wether the starting 9 characters match the current date and if that matches u can extract that particular line. if u need the code then pls let me know.
0
 

Author Comment

by:Schurink
Comment Utility
Hi,
At the moment we use DOS to do that, but in that case we need to manualy change the script every day. To avoid that and have a fully automated process in obtaining the right data we want to use vbs.
So what we use now is :
   set DATE=9/14/2004
   find "%DATE%" "C:\..\ScanLog.txt" >>E:\blahblah.log
But this requires a manual change in the script every day.
So if someone has the solution for this (automating this process), please write down the script/code...
Cheers!


0
 
LVL 7

Expert Comment

by:_agj_
Comment Utility
i think u can use:

date /T
to get the current date...but that includes the day also...Fri etc...

can strip this off and set it to a varaible...then the same script.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
Comment Utility
i could tell you how you could do this in vb6,but not in vb script.tell me if you're interested
0
 

Author Comment

by:Schurink
Comment Utility
Well that's a solution too, to echo the %date% and strip off the first 4 characters. Then the result  is the same.  I've been searching some resource kits to achieve this, but could not find any tool applicable.
Any idea what the code should be to strip it off and set it to a new variable?
0
 
LVL 16

Expert Comment

by:jimbobmcgee
Comment Utility
You could use the inbuilt Date function to parse the current date.  Then it would be a case of, as itmastero said, opening the file, reading each line and checking if that is found:

Dim ReadString
Dim DateString
Dim LogFile

DateString = CStr(Date)         ' Convert todays date to a useable string
LogFile = "c:\log"                   ' Your log's path and file name

Set fso = CreateObject("Scripting.FileSystemObject")                ' Create a file system object
Set ts = fso.OpenTextFile(LogFile, 1)                      ' Open the logfile

Do until ts.AtEndOfStream                   ' Repeat this section until the end of the file

      ReadString = ts.ReadLine                ' Read a line into a buffer
      if Instr(1, ReadString, DateString) then             ' If todays date is inside the read line, do this
            
            msgbox ReadString                 ' Show the line in a message box (change for your code)

      End if

Loop                    ' Go back to Do until ...

That would only do something for lines with todays date in them.  The date format for your machine and the log file would have to match, though...
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
you don't need to change the script, just parameterize the date going into your batch file.  Use %1 to reference the value passed in from the command line.
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
PAQed with no points refunded (of 125)

modulo
Community Support Moderator
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now