#!/usr/bin/awk -f BEGIN { stages = " " } /^target: / { n = split(stages, l, " ") for (i = 1; i <= n; i++) { switch (l[i]) { case /.*\.(get|extract|prepare|compile|install|targetinstall|urlcheck|srchash|cfghash)(.[a-z]+)?/: break # other stuff, such as archive downloads may not have a explicit end # so stop them when the next target starts default: drop(l[i]) break } } stages = stages $2 " " cache[$2][0] = last } function drop(stage) { delete cache[stage] do { old = stages stages = gensub(" " stage " ", " ", "g", stages) } while (old != stages) } /\> targetfile } close(targetfile) drop(stage) } } /^({{{|}})/ { for (stage in cache) drop(stage) }