You can remove empty lines on a fly using “sed” in  a shell.  This is how

sed '/^$/d' input.txt > output.txt

Input:

and
by
but

 

Output:

and
 by
 but