- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Remove Empty Lines from a File on ubuntu
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!
- How to remove empty string/lines from PowerShell?
- Remove new lines from a string and replace with one empty space PHP?
- How to remove end lines from a boxplot in R?
- Python | Remove empty tuples from a list
- How to remove an empty string from a list of empty strings in C#?
- How to removes duplicate lines from a sorted file in Linux?
- How do I remove lines between listviews on Android?
- How to remove lines in a Matplotlib plot?
- How to remove a committed file from the Git repository?
- How to remove empty strings from a list of strings in Python?
- Remove new lines from string in PHP
- How to remove empty rows from an R data frame?
- How to read a file from assets on android?
- How to remove grid lines from an image in Python Matplotlib?
- C program to remove a line from the file