Skip to content

Instantly share code, notes, and snippets.

@Inndy
Last active August 29, 2015 14:05
Show Gist options
  • Save Inndy/7f4d04ee95d7beb59f59 to your computer and use it in GitHub Desktop.
Save Inndy/7f4d04ee95d7beb59f59 to your computer and use it in GitHub Desktop.
awk parser for ctftime.org
#!/usr/bin/env gawk -f
BEGIN {
format = "%-8s%-8s%-12s%s\n"
for (i = 0; i < ARGC; i++) {
if (ARGV[i] == "--csv") {
format = "%s,%s,%s,\"%s\"\n"
}
delete ARGV[i]
}
printf(format, "Place", "TeamID", "Score", "TeamName")
}
{
if (match($0, /<td class="place( leader)?">([0-9]+)<\/td>$/, arr))
{
no = arr[2]
}
else if (match($0, /^<td><a href="\/team\/([0-9]+)">(.+)<\/a><\/td>$/, arr))
{
id = arr[1]
name = arr[2]
}
else if (match($0, /^<td class="points">([0-9\.]+)<\/td>/, arr))
{
score = arr[1]
printf(format, no, id, score, name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment