Solved

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

Posted on 2004-09-17
11
157 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

749 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