Skip to content

Instantly share code, notes, and snippets.

@imranbhullar
Last active June 16, 2019 02:59
Show Gist options
  • Save imranbhullar/7394d061ef47cb268f983a7e648657f7 to your computer and use it in GitHub Desktop.
Save imranbhullar/7394d061ef47cb268f983a7e648657f7 to your computer and use it in GitHub Desktop.
Parsing Apache logs to a CSV using python
#Parsing apache logs to a CSV using python
import csv
OutputCsv = open("/some/path/output.csv",'wb')
Writer = csv.writer(OutputCsv)
header = ['User Address', 'Date/Time', 'Action', 'Requested URL', 'Return Code', 'Size']
Writer.writerow(header)
f = open('/some/path/http_logs.log', 'r')
for line in f:
line = line.split()
line = line[0:4] + line[5:7]
Writer.writerow(line)
OutputCsv.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment