Remove empty lines in a text file via grep

user191960 picture user191960 · Oct 23, 2009 · Viewed 111.7k times · Source

FILE:

hello

world

foo

bar

How can I remove all the empty new lines in this FILE?

Output of command:

FILE:

hello
world
foo
bar

Answer

DigitalRoss picture DigitalRoss · Oct 23, 2009

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)