Solved

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

Posted on 2004-09-17
11
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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 46

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

617 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