Last active
August 29, 2015 14:05
-
-
Save Inndy/7f4d04ee95d7beb59f59 to your computer and use it in GitHub Desktop.
awk parser for ctftime.org
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
#!/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