My solution is to put a surplus line (with bash) at the end of the file. In my case a simple 'echo "" >>$FILENAME' was enough, but you could put an 'echo "%%ENDOFFILE%%" >> $FILENAME' as well.