[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBscript to strip off columns in a text file

Posted on 2008-11-18
9
Medium Priority
?
559 Views
Last Modified: 2012-06-27
Hi Experts:
Could someone help me create a vbscript that can strip off "Event" "Source" "Description" columns off the text file I attached and put the rest into a new text file?

Thanks
0
Comment
Question by:changjia
  • 5
  • 4
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22990400
Where's the file?
0
 

Author Comment

by:changjia
ID: 22990454
sorry, wrong file. Here it is again.
test3.txt
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22991359
Here's the situation...it looks like you're using a script to dump the data.  Whatever method is dumping it in seemingly neat columns, but they're delimeted by spaces and tabs, so there's no easy way to sort through this data.

What about a script to simply read the event log and output only the fields you want?  Would that work?
0
Industry Leaders: 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!

 

Author Comment

by:changjia
ID: 22991568
yes. That would work. I used eventquery.vbs located in c:\windows\system32 to generate the report. I just can't seem to find any script that can do similar things...
0
 

Author Comment

by:changjia
ID: 22991611
Actually, I know a way of out putting the file without the Descrition column. Is there a way to add a column called Category into the text file? The output needs to be like this

Type             Event    Date Time                          ComputerName   Category        User    
audit failure 537        11/17/2008 10:40:27 PM     C2826          Logon/Logoff    NT AUTHORITY\SYSTEM  

Is this possible to do?

Thanks
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22993813
Okay, I ran that script using the following parameters:

cscript %systemroot%\system32\eventquery.vbs /fo /csv /v /l security > c:\security.log

Then this script should grab just the columns you need...
LogFile = "C:\security.log"
NewLog = "C:\newlog.txt"
 
ColumnsToRecord = Array(0,1,2,4,5,6)
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(LogFile)
Dim objOut : Set objOut = objFSO.CreateTextFile(NewLog)
 
'Skip header data
For x = 0 to 4
  objFile.ReadLine
Next
 
strHost = objFile.ReadLine
objOut.WriteLine "Results for:" & Replace(mid(strHost, Instr(strHost, "host")+4),chr(39),"")
objOut.WriteLine 
 
For x = 0 to 2
  objFile.ReadLine
Next
 
Do While Not objFile.AtEndOfStream
  strRead = objFile.ReadLine
  If Trim(strRead) <> "" Then
    arrData = Split(strRead, ",")
    For Each item in ColumnsToRecord
      strData = strData & vbTab & arrData(item)
    Next
    objOut.WriteLine Mid(strData,2)
    strData=""
  End If
Loop
 
objOut.Close
objFile.Close

Open in new window

0
 

Author Comment

by:changjia
ID: 22994132
Sirbounty:
T
he newlog.ext only shows me a result like this:
Please view the attached text file.

What is the top line of text? Is there a way to remove them?


Thanks



newlog.txt
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 22994581
Odd - I was trying to grab the hostname for you as well...
Either attach the original log (snippet is fine) or try this version, which skips all the header info...
LogFile = "C:\security.log"
NewLog = "C:\newlog.txt"
 
ColumnsToRecord = Array(0,1,2,4,5,6)
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(LogFile)
Dim objOut : Set objOut = objFSO.CreateTextFile(NewLog)
 
'Skip header data
For x = 0 to 7
  objFile.ReadLine
Next
 
Do While Not objFile.AtEndOfStream
  strRead = objFile.ReadLine
  If Trim(strRead) <> "" Then
    arrData = Split(strRead, ",")
    For Each item in ColumnsToRecord
      strData = strData & vbTab & arrData(item)
    Next
    objOut.WriteLine Mid(strData,2)
    strData=""
  End If
Loop
 
objOut.Close
objFile.Close

Open in new window

0
 

Author Comment

by:changjia
ID: 23089960
Thanks for the help!
I actually had to use Perl to do this. It is much easier than using VBscript.

But thank you very much for the help!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

826 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