102

I have a text file with a thousand lines of numbers like so:

402

115

90

...

As you can see there is a blank line in between each number that I want to remove so that I have

402
115
90
...

How can I do this?

icktoofay
  • 126,289
  • 21
  • 250
  • 231
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
  • 6
    That move-to-SU voter, just put [notepad++] in your ignored tags and move on, because [questions about a programmer's text editor are allowed here](http://stackoverflow.com/faq#questions). – BoltClock Aug 07 '11 at 17:18

6 Answers6

192
  1. Press Ctrl+H (Replace)

  2. Select Extended from SearchMode

  3. Put \r\n\r\n in Find What

  4. Put \r\n in ReplaceWith

  5. Click on Replace All

Replace multiple line breaks

YetAnotherUser
  • 9,156
  • 3
  • 39
  • 53
167

As of NP++ V6.2.3 (nor sure about older versions) simply:

  1. Go menu -> Edit -> Line operations
  2. Choose "Remove Empty Lines" or "Remove Empty Lines (Containing white spaces)" according to your needs.
starball
  • 20,030
  • 7
  • 43
  • 238
Liudas
  • 1,671
  • 1
  • 10
  • 2
  • I'm trying this, but on a file with about 1.5 million empty rows. The program is just freezing. I'm not sure if it has crashed or just working through all of these rows. – Joshua Schlichting Apr 06 '17 at 12:44
  • A bit too late maybe, but for 1.5 million empty rows make a program, I recommend to use Perl a scripting langauge that works very well with text operations. – Eduardo Oct 04 '17 at 08:17
22

By the way, in Notepad++ there's built-in plugin that can handle this: TextFX -> TextFX Edit -> Delete Blank Lines (first press CTRL+A to select all).

jakub.g
  • 38,512
  • 12
  • 92
  • 130
5

This will remove any number of blank lines

CTRL + H to replace

Select Extended search mode

replace all \r\n with (space)

then switch to regular expression and replace all \s+ with \n

Griffin
  • 13,184
  • 4
  • 29
  • 43
1

This should get your sorted:

  • Highlight from the end of the first line, to the very beginning of the third line.
  • Use the Ctrl + H to bring up the 'Find and Replace' window.
  • The highlighed region will already be plased in the 'Find' textbox.
  • Replace with: \r\n
  • 'Replace All' will then remove all the additional line spaces not required.

Here's how it should look: enter image description here

Dustin Cook
  • 1,215
  • 5
  • 26
  • 44
  • Using NP++ 7.8.1 this is the only solution that works for me. I don't understand why I cannot find "\r\n\r\n" used in the many other solutions. – BillDarcy Dec 06 '19 at 20:14
1

You can record a macro that removes the first blank line, and positions the cursor correctly for the second line. Then you can repeat executing that macro.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210