Saturday, December 20, 2014

Unix - Delete blank lines from file


Here's some ways to remove empty or blank lines from a file in Unix. Simple but definitely useful.
$ grep -v '^$' file.txt
$ grep '.' file.txt
$ sed '/^$/d' file.txt
$ sed -n '/^$/!p' file.txt
$ awk NF file.txt
$ awk '/./' file.txt

In Vi editor, in escape mode type
:g/^$/ d
Related posts:

1 comment:

Adithya Kiran said...

Another way..
$ grep . file.txt

© Jadu Saikia www.UNIXCL.com