1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env bash if ! [[ -n "$1" || -n "$2" ]]; then printf "%s\n" "awink <infile> <outfile>" exit 2 fi gawk '{ if (NF == 2 && $1 == "%include") { while ((getline line < $2) > 0) { print line; } close($2); } else { print; } }' "$1" > "$2"