I'm attempting to parse some event logs into a .csv from a .log format so my event manager software can read it.
I'm trying to search a folder for all files ending in a .log extension, then look at each line for the word "Security," separate the values by tab and paste those values into a .csv file automatically created.
The problem is when the data is pasted it adds extra rows and rb into the file. An example would be: row 1: data, row 2: blank, row 3: rb, row 4: blank, row 5: data, etc.
This is what I'm currently working with.
import sys, random, os, csv, fileinput, glob, re, pygame
from os import path
import time as t
date = t.localtime(t.time())
destination = raw_input("Give the path of your file: ")
for logtest in glob.glob(destination +"*.log"):
logname = logtest[:-4]
assert os.path.exists(logtest), "No file was found at, "+str(logtest)
name = "Log_Filter_%d_%d_%d_%d_%d_%d.csv" %(date[1], date[2], (date[0] %100), date[3], date[4], date[5])
auditlog = open(logtest, "r")
if not(path.isfile(destination + name)):
splittestfile = csv.writer(open(destination + name, "a"))
for x in auditlog:
if "Security" in x:
splitstr = csv.reader((x, "rb"), delimiter = "\t")
splittestfile.writerows(splitstr)