#!/usr/bin/awk -f BEGIN { stages = " " } /^target: / { n = split(stages, l, " ") for (i = 0; i < n; i++) { switch (l[i]) { case ".*.(get|extract|prepare|compile|install|targetinstall|urlcheck)(.[a-z]+)?": stages = stages " " l[i] break # other stuff, such as archive downloads may not have a explicit end default: 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) }