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.