perl -ne 's/\r$// or last; $t.=$_; if (eof) {close ARGV; open $fh, ">", $ARGV or die; print $fh $t}' files