x=readChar("stdin", 1e6) a=gsub("@i","%s",sub("\\$\n.*","",x)) b=strsplit(strsplit(sub(".*\\$\n1\n","",x),"\n1\n")[[1]],"\n") for(d in b)cat(do.call("sprintf", c(list(fmt=a),as.list(d))))
Note that non-ascii characters in the above source code will be escaped (such as \x9f).