Last active
June 16, 2019 02:59
-
-
Save imranbhullar/7394d061ef47cb268f983a7e648657f7 to your computer and use it in GitHub Desktop.
Parsing Apache logs to a CSV using python
This file contains hidden or 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
#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