Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-17
11
Medium Priority
?
162 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
9 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

877 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