nl=' ' key=$1 shift awk -v 'key='$key ' BEGIN{ collect = 0; systarg = ENVIRON["SYSTARG"]; model = ENVIRON["TARGMODEL"]; } /^$/{ next; } /^#/{ next; } collect && /^[^ \t]/{ collect = 0; } collect && $0 ~ /[^ \t]+/{ targ[ntarg++] = $1; } $0 ~ /^[^ \t]/{ if($1 == key){ for(i = 2; i <= NF; i++){ if($i == "*") collect = 1; else if($i == ("targ=" systarg)) collect = 1; else if($i == ("model=" model)) collect = 1; } } next; } END{ for(i = 0; i < ntarg; i++) x = x " " targ[i] "\n" printf substr(x, 1); }' $* | sed 's/ //'