• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

VBscript to strip off columns in a text file

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
changjia
Asked:
changjia
  • 5
  • 4
1 Solution
 
sirbountyCommented:
Where's the file?
0
 
changjiaAuthor Commented:
sorry, wrong file. Here it is again.
test3.txt
0
 
sirbountyCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
changjiaAuthor Commented:
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
 
changjiaAuthor Commented:
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
 
sirbountyCommented:
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
 
changjiaAuthor Commented:
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
 
sirbountyCommented:
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
 
changjiaAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now