Solved

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

Posted on 2004-09-17
11
154 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_
ID: 12082825
use dos to do that:

find "9/17/2004" mcafee.log

will list all lines containign this date
0
 

Expert Comment

by:itmastero
ID: 12082862
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
ID: 12082947
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_
ID: 12083012
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 12083164
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
ID: 12083292
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
ID: 12084705
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
ID: 12094022
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
ID: 12752453
PAQed with no points refunded (of 125)

modulo
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 115
Excel VBA combine two working workbooks 8 47
using web browser with BING 40 110
TT Auto Dashboard 13 85
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

895 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

18 Experts available now in Live!

Get 1:1 Help Now