Skip to content

Instantly share code, notes, and snippets.

@kirang89
Created December 13, 2015 16:49
Show Gist options
  • Save kirang89/cc2458d4421dbcd868f0 to your computer and use it in GitHub Desktop.
Save kirang89/cc2458d4421dbcd868f0 to your computer and use it in GitHub Desktop.
A simple example to illustrate log file parsing using AWK
#!/usr/bin/awk -f
BEGIN {
requests = 0
getrq = 0
postrq = 0
count = 0
}
$0 ~ /(GET|POST)/ {
requests++;
if ($9 == "200") count++;
}
$0 ~ /GET/ {
getrq++;
# Remove a leading bracket from date column
sub(/^\[/, "", $4);
print $4 " <" $7 "> => " $9;
}
$0 ~ /POST/ {
postrq++;
}
END {
print "Total Requests: " requests;
print "GET Requests: " getrq;
print "POST Requests: " postrq;
print "200 served: " count;
print "success rate: " (count/requests)*100 "%"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment