#! /usr/bin/awk -f /^[ \t]*#\$.*/ { match($0,/^[ \t]*/) whitespace=substr($0,RSTART,RLENGTH) match($0,/#\$.*/) command=substr($0,RSTART+2,RLENGTH) while (command | getline line) print whitespace line } !/^[ \t]*#\$.*/ { print $0 }