Created
September 28, 2016 14:18
-
-
Save marcom04/8905509e53f320c8cd04a9e80d1a9be4 to your computer and use it in GitHub Desktop.
Converts a generic log file with separated fields into CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
events = ("warning", "Warning", "error", "Error") # put here strings of interest in log | |
log_file = sys.argv[1] | |
log_separator = ':' | |
csv_file_name = log_file + ".csv" | |
csv_separator = ';' | |
csv_file = open(csv_file_name, 'w') | |
for line in open(log_file, 'r'): | |
if line in ['\r', '\r\n']: | |
continue | |
if any(e in line for e in events): | |
fields = line.split(log_separator) | |
line = csv_separator.join(fields) | |
csv_file.write(line) | |
csv_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment