Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/awk -f
- BEGIN { w = "[a-zA-Z_][a-zA-Z0-9_]*"; var = sprintf("\\$(%s|{%s})", w, w) }
- {
- str = ""
- tail = $0
- while (match(tail, var)) {
- head = substr(tail, 1, RSTART - 1) # text before match
- repl = substr(tail, RSTART, RLENGTH) # match to replace
- tail = substr(tail, RSTART + RLENGTH) # text after match
- if ((match(head, /\\+/) ? RLENGTH + 1 : 1) % 2 == 1) {
- sub(/^\$/, "", repl)
- gsub(/(^{|}$)/, "", repl)
- repl = ENVIRON[repl]
- }
- str = str head repl
- }
- str = str tail
- print str
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement