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
changjiaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.