Created
October 21, 2013 22:38
-
-
Save samjsharpe/7092121 to your computer and use it in GitHub Desktop.
Quick script to parse a web log (in custom format) looking for three images (with|without|base)-js, counting the occurrences and spit out a report on the useragents that grabbed without-js. Usage: gawk -f counter.awk <logfile>
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
$7 ~ /(without|with|base)-js/ { | |
split($7,array,"-"); | |
target_string=array[2]; | |
split(target_string,array2,"/"); | |
image=array2[2]; | |
switch (image) { | |
case "with": | |
WITH+=1 | |
break | |
case "without": | |
WITHOUT+=1 | |
useragent="" | |
for (i=8;i<=NF;i++) { | |
useragent=useragent " " $i; | |
} | |
useragents[useragent]+=1 | |
break | |
case "base": | |
BASE+=1 | |
break | |
} | |
SUM+=1 | |
if (SUM % 100000 == 0) | |
printf " " SUM " lines processed so far\n"; | |
else if (SUM % 2000 == 0) | |
printf "."; | |
} END { | |
printf " " SUM " lines processed\n"; | |
print "Totals,," > "report.csv"; | |
print "with-js," WITH >> "report.csv"; | |
print "without-js," WITHOUT >> "report.csv" ; | |
print "base-js," BASE >> "report.csv" ; | |
print "difference," BASE-WITH-WITHOUT ",(base-js - with-js - without-js)" >> "report.csv"; | |
print "best %," (WITHOUT*100)/BASE ",(assuming that hits on without-js is people without js)" >> "report.csv"; | |
print "worst %," ((BASE-WITH)*100)/BASE ",(assuming that (base-js - with-js) is people without js)" >> "report.csv"; | |
print ",," >> "report.csv" | |
print "Summary data for hits on without-js by user-agent,," >> "report.csv" | |
print ",," >> "report.csv" | |
print "Hits,UserAgent" >> "report.csv" | |
for (var in useragents) | |
{ | |
print useragents[var] "," var "," >> "report.csv" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment