# How to Remove Empty Lines from a File on ubuntu

UbuntuFile SystemSoftware & Coding

Do you know how to remove empty lines from the file in Ubuntu? It may also be performed manually if the file has few strains but if the file has hundreds of thousands of line that is tough to be accomplished manually. This article explains you about – how to remove empty lines from a file on Ubuntu.

Our sample file should be like this –

Use the following command to remove the Empty lines from a file as shown below –

$ex -s +'v/\S/d' -cwq abc.txt In the above command abc.txt indicates the file name. The sample output should be like this – To create a new file without empty lines from the previous file, use the following command – $ awk 'NF > 0' abc.txt > bbc.txt

In the above command, it creates a file called bbc.txt and copies the whole content from abc.txt without empty lines. To verify the file, use the following command –

\$ nano bbc.txt

The sample output should be like this –

In the above file, it has deleted empty lines and created the result in another file called bbc.txt in the same directory.

In the above article, we have learnt – Learn how to Remove Empty Lines from a File on ubuntu. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!

Published on 20-Jan-2020 10:45:11