Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix something #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import re
import sys

#fetch filename
import os.path


if len(sys.argv) > 1:
filename = str(sys.argv[1])
else:
Expand All @@ -14,7 +18,7 @@
except:
raise Exception("Invalid input file")
# Regex matches "field=value" or "field=""more words""" syntax
pattern = re.compile('(\w+)(?:=)(?:"{1,3}([\w\-\.:\ =]+)"{1,3})|(\w+)=(?:([\w\-\.:\=]+))')
pattern = re.compile('(\w+)(?:=)(?:"{1,3}([\w\-\.:\ =\+/%\(\)\[\],\?/\*>]+)"{1,3})|(\w+)=(?:([\w\-\.:\={}/]+))')
events = [] # List to hold individual event dicts

for line in log_data:
Expand All @@ -36,8 +40,9 @@
headers.append(key) # Compile a deduped list of headers

print("[+] Writing CSV")
newfilename = (filename.split(
"/")[len(filename.split("/"))-1].split('.')[0])+'.csv' # Get base file name from logfile

newfilename = os.path.splitext(filename)[0]+'.csv' # Get base file name from logfile

#Added the newline option to prevent blank rows from outputting to CSV
with open(newfilename, 'w', newline='') as fileh:
csvfile = csv.DictWriter(fileh, headers) # Write headers
Expand Down