Skip to content

Instantly share code, notes, and snippets.

@xenji
Created March 30, 2013 19:35
Show Gist options
  • Save xenji/5278053 to your computer and use it in GitHub Desktop.
Save xenji/5278053 to your computer and use it in GitHub Desktop.
function isNoHomepageSearch(input) {
return input !~ /bIsWorldwide/
}
function getIp(input) {
return $3
}
function isGetRequest(input) {
return input ~ /^"GET/
}
function getPathId(input) {
match(input, /iPathId=([0-9])+/, pathId)
if (length(pathId) > 0) {
return pathId[0]
}
}
function getPathList(input) {
match(input, /aPathList=([0-9,])+/, pathList)
if (length(pathList) > 0) {
return pathList[0]
}
}
function join(array, start, end, sep, result, i) {
if (sep == "")
sep = " "
else if (sep == SUBSEP) # magic value
sep = ""
result = array[start]
for (i = start + 1; i <= end; i++)
result = result sep array[i]
return result
}
BEGIN {
pathListPart[0] = ""
pathPart[0] = ""
use_pathlist = 0
}
{
if (isNoHomepageSearch($7) && isGetRequest($6)) {
rawPathId = getPathId($7)
if (use_pathlist == 1)
rawPathList = getPathList($7)
if (rawPathId != "") {
match(rawPathId, /([0-9]+)/, pathPart)
}
if (use_pathlist == 1 && rawPathList != "") {
match(rawPathList, /([0-9,]+)/, pathListPart)
}
if (length(pathPart) > 0 && (use_pathlist == 1 && length(pathListPart) > 0))
final = pathPart[0] "," pathListPart[0]
else if (use_pathlist == 1 && length(pathListPart) > 0)
final = pathListPart[0]
else
final = pathPart[0]
print $3 ";" final
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment