by Jeremy Canfield | Updated October 12th, 2018
Let's say file.txt contains empty lines.
Hello World How are you today?
The following sed command will remove the empty lines. The regular expression looks for whitespace (\s*) from the beginning (^) to the end ($) of each line, and if matched, deletes (d) the line.
~]# cat file.txt | sed '/^\s*$/d' Hello World How are you today?