You can open files dynamically using `getline', `close', and `print EXPR > FILENAME', like:
# assumes input file has at least 1 line, output file writeable function double(infilename,outfilename, aline) { while ( (getline aline < infilename) >0 ) print(aline aline) > outfilename; close(infilename); close(outilename); }