in reply to Remove Blank Lines Off the End of a File


Here is a one-liner. On an arbitrary test system it took 4 seconds to process a 3 meg file.

The changes are made in-place so change -i to -i.bak if you want to keep a backup. perl -i -ne '/^$/ ? $i++ : do{print "\n" x $i, $_; $i=0}' file Update: I just ran PrakashK's program on the same test data. It took 0.1 sec!!

--
John.