From 1a019e1d67be3e543e61e3fd6e19d4007dfb3c80 Mon Sep 17 00:00:00 2001 From: Michael Stanton Date: Thu, 18 Dec 2014 09:10:13 +0100 Subject: [PATCH] make-ic-history is for work, but a nice awk example. --- scripts/make-ic-history.sh | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/make-ic-history.sh diff --git a/scripts/make-ic-history.sh b/scripts/make-ic-history.sh new file mode 100755 index 0000000..f29da43 --- /dev/null +++ b/scripts/make-ic-history.sh @@ -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 \ No newline at end of file