Friday, December 5, 2008

Delete blank lines in vi editor


Simple but useful vi editor tip.

Q. How can I delete any blank lines within a file in vi editor?

Ans:
In escape mode type

:g/^$/ d

And all your blank lines should be removed !!

Other ways of removing blank lines from a file using grep, awk and sed

$ grep -v '^$' file
$ grep '.' file
$ sed '/^$/d' file
$ sed -n '/^$/!p' file
$ awk NF file
$ awk '/./' file

1 comment:

Balaji Prasad said...

Thank you, it was very helpful.

© Jadu Saikia www.UNIXCL.com