Delete blank lines using vi editor
Submitted by admin on Thu, 12/11/2008 - 05:56.
Here's a very handy option to delete blank lines from a text file on Unix.
If it's a one time operation, you don't want to spend time writing a script for it.
Open the file using 'vi' editor [ # vi testfile.txt ]
Hit 'Esc' key to ensure you are in command mode.
Type :g/^$/d and hit Enter. You are done.
Here ^ means beginning of the line and $ means end of line (a blank line with no characters on it). 'd' means delete.
If there are space characters on the blank line, you could do this:
:g/^ *$/d
which means it will look for lines with one or more spaces and delete it.
Have fun.