Created
August 9, 2012 00:07
-
-
Save wezm/3299869 to your computer and use it in GitHub Desktop.
Script to extract stats from web server access logs
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/awk | |
BEGIN { | |
# Use tab as output field separator | |
OFS=" " | |
} | |
# Extracts the device family from the full device | |
# E.g iPhone from iPhone4,1 | |
function device(full) { | |
idx = match(full, /[0-9]/); | |
return substr(full, 1, idx - 1) | |
} | |
# /packs.xml?device=iPhone2,1&os=5.1.1 | |
$7 ~ /\/packs\.xml\?/ { | |
# Get the query string | |
path = $7 | |
sub(/^\/packs\.xml\?/, "", path) | |
# Split into key value pairs | |
split(path, parts, /&/) | |
for (part in parts) { | |
# Split the pair | |
split(parts[part], pair, /=/) | |
# Add to the os count | |
if (pair[1] == "os") { | |
os[pair[2]]++ | |
} | |
# Add to the device count by specific device and device family | |
if (pair[1] == "device") { | |
fulldevices[pair[2]]++; | |
devices[device(pair[2])]++ | |
} | |
} | |
} | |
END { | |
# Print the results | |
for (name in os) { | |
print name, os[name] | |
} | |
print "" | |
for (name in fulldevices) { | |
print name, fulldevices[name] | |
} | |
print "" | |
for (name in devices) { | |
print name, devices[name] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment