I have a file (hosts) with some lines without content, how do I remove that lines without content?
sedand edit the file in place.
sudo sed -i -rn '/\S/p' /etc/hosts
Same, but with Perl:
sudo perl -i -ne 'print if /\S/' /etc/hosts
Newer versions of GNU
awk, in place again:
sudo awk -i inplace '/\S/' file
All of the above solutions will also remove lines that contain nothing but whitespace. If you only want to remove empty lines, and leave lines that contain spaces or tabs etc, change the
/^$/ in all of the above examples.