Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to delete all the blank lines in a text file. Is there a quick way to do this?

What I have

line one

line two

What I want

line one
line two

I am using Notepad++, so a solution using Notepad++ is appreciated.

I have Cygwin too, so if nothing else, a script is fine.

share|improve this question
add comment

4 Answers

In Cygwin:

$ sed -i '/^$/d' <name_of_your_textfile.txt>

Or, if the "blank lines" are allowed to contain tabs and spaces:

$ sed -i '/^[ \t]*$/d' <name_of_your_textfile.txt>

The -i stands for "edit in place", so if your text files are valuable you might want to use the commands without the -i and pipe the output to a different file, look at the results and then rename it.

Using Vim (should come with Cygwin, but there is also a native Windows version):

:%g/^[ \t]*$/d

This has the advantage that you directly see your results and can undo them by pressing "u". You also might encounter fewer problems with Windows' line endings (depends on your Cygwin configuration).

share|improve this answer
add comment

Use the menu:

1) Select all text (Ctrl-A)

2) TextFX -> TextFX Edit -> Delete Blank Lines

share|improve this answer
1  
Thanks, Efficient method. –  greyDrifter Sep 3 '09 at 21:22
add comment

Switch to Extended search mode in the Replace dialog.

Find what: \r\n\r\n

Replace with: \r\n

Press Replace All. All the blank lines are gone.

share|improve this answer
1  
This does strongly depend on the line ending format used in the file. –  Manuel Faux Sep 3 '09 at 21:24
2  
or \n\n to \n for *nix –  pelms Sep 3 '09 at 21:51
add comment

Macro's can be scary, accidental loss the first chars if its off a line..

  • View > Show Symbols > Show End Of Line

Take note that it ends in CR LF (This is Carriage Return and Line Feed which is \r\n) Ctrl+H then enable extended replace "\r\n\r\n" with "\r\n"

It will cycle through and remove the double spacing, you might need to repeat if its more than just double spacing. (Another thing to consider is: Edit > Trim Trailing White Space.)

share|improve this answer
add comment

protected by Diago Nov 9 '10 at 6:43

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.