Created
September 2, 2015 22:31
-
-
Save juster/11d2cbc7d11f84e481c1 to your computer and use it in GitHub Desktop.
Tiny awk web template
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
function die (msg) | |
{ | |
printf "%s:%d %s\n", FILENAME, FNR, msg > "/dev/stderr" | |
exit 1 | |
} | |
BEGIN { FS="{!}"; OFS="" } | |
NF > 0 && NF % 2 == 0 { die("Unbalanced {!} tokens.") } | |
NF > 2 { | |
for (i=2; i<=NF; i+=2) { | |
if (!match($i, "^[A-Za-z]+$")) { | |
die("Invalid variable name: \"" $i "\"") | |
} | |
if (ENVIRON[$i] == "") { | |
die("Undefined variable: \"" $i "\"") | |
} | |
$i = ENVIRON[$i] | |
} | |
} | |
{ print } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment