Skip to content

Commit

Permalink
make-ic-history is for work, but a nice awk example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ripsawridge committed Dec 18, 2014
1 parent 2003f3e commit 1a019e1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions scripts/make-ic-history.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
awk '
BEGIN {
site_attributes[""] = 0
site_history[""] = 0
}
{
if (/^\[.+ in ~/) {
type = substr($1, 2)
location = $3
if ($5 == "native") {
state = $7
source = $6
} else {
state = $6
source = $5
}
if (site_attributes[location] == "") {
site_attributes[location] = type " " source
}
if (site_history[location] == "") {
site_history[location] = state
} else {
site_history[location] = site_history[location] " " state
}
# print NF, location, state
}
}
END {
# Canonicalize the site name, reducing foo+256, foo+17 to foo+2, foo+1.
function_to_site[""] = 0
for (i in site_attributes) {
split(i, split_output, "+")
function_to_site[split_output[1]] = function_to_site[split_output[1]] " " split_output[2]
}
site_to_canon[""] = 0
for (i in function_to_site) {
split(function_to_site[i], split_output, " ")
len = asort(split_output, sort_output)
for (j = 1; j <= len; j++) {
site_to_canon[i "+" sort_output[j]] = i "+" j
}
}
# print the site attributes and history
for (i in site_attributes) {
if (i != "") {
print site_to_canon[i], site_attributes[i], site_history[i]
}
}
} ' | sort -k 3

0 comments on commit 1a019e1

Please sign in to comment.