Remove empty lines from a file in Linux bash

Home > Search
  by

Let's say file.txt contains empty lines.

Hello

World

How

are

you

today?

 

The following sed command will remove the empty lines.

~]# cat file.txt | sed '/^\s*$/d'
Hello
World
How
are
you
today?

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments