Skip to content

Instantly share code, notes, and snippets.

@marcom04
Created September 28, 2016 14:18
Show Gist options
  • Save marcom04/8905509e53f320c8cd04a9e80d1a9be4 to your computer and use it in GitHub Desktop.
Save marcom04/8905509e53f320c8cd04a9e80d1a9be4 to your computer and use it in GitHub Desktop.
Converts a generic log file with separated fields into CSV file
#!/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