Preprocess Apache Logs for Evaluation

by Wolfram Saringer  (2011-11-09)
last change: 2011-11-09


This simple shellscript converts standard Apache common logfiles to a CSV format (note the tabs in the replacement pattern between each column):


#!/bin/sh
echo "IP\tTag\tMonat\tJahr\tUhrzeit\tURL\tStatus\tTransfer"
# 1: IP
# 2: day
# 3: month
# 4: year
# 5: time
# 6: url
# 7: protocol
# 8: status code
# 9: transfer in bytes

cat $1 | \
sed -E 's/(.*) \- \- \[([0-9]*)\/([A-Z][a-z]*)\/([0-9]*):(.*) \+[0-9]*\] "GET (.*) HTTP\/(.*)" +([0-9]*) ([0-9]*) "(.*)" .*/\1 \2 \3 \4 \5 \6 \7 \9/g'


all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.