How To Remove All Blank Lines using Sed or VIM


The regular expressions simplify our lives. For example, if you want to remove all blank lines (empty), instead of writing any scripts or programs, you can simply use the following command line:

1
cat filename.txt | sed "/^$/d"
cat filename.txt | sed "/^$/d"

Under VI/VIM text editors, you can issue the similar commands (type in colon to start commands):

1
g/^[ ]*$/d
g/^[ ]*$/d

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
105 words
Last Post: How to Make First Letter in First Paragraph Big in WordPress (CSS) articles?
Next Post: How to Fix Visual Studio Search in Files Not Displaying List of Files Error?

The Permanent URL is: How To Remove All Blank Lines using Sed or VIM (AMP Version)

Leave a Reply