Remove empty lines in a text file via grep
with awk, just check for number of fields. no need regex
$ more file
hello
world
foo
bar
$ awk 'NF' file
hello
world
foo
bar
Try the following:
grep -v -e '^$'
Here is a solution that removes all lines that are either blank or contain only space characters:
grep -v '^[[:space:]]*$' foo.txt
grep . FILE
(And if you really want to do it in sed, then: sed -e /^$/d FILE
)
(And if you really want to do it in awk, then: awk /./ FILE
)