-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make-ic-history is for work, but a nice awk example.
- Loading branch information
1 parent
2003f3e
commit 1a019e1
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |