Notepad++ - How can I replace blank lines [duplicate]
Asked Answered
R

6

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?

Reichel answered 7/8, 2011 at 17:15 Comment(1)
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.Blackcap
O
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

Outlaw answered 7/8, 2011 at 17:20 Comment(5)
Actually, this only works if there are only two new lines between each line of text.Orlantha
@Griffin: The duplicate link I mention beneath the question goes beyond exactly two blank lines.Blackcap
@YetAnotherUser: It's a plugin that ships with current Notepad++ installations by default. Or at least, as far as I can remember it does...Blackcap
In my case, there were several blank lines instead of 2. Repeated click on "Replace All" did the trick.Carnatic
Didn't work for me :( the trick edit->line operations->remove empty lines worked perfectly.Kobylak
L
169

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.
Lettielettish answered 4/3, 2013 at 11:36 Comment(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.Infundibuliform
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.Veinstone
P
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).

Polygon answered 14/9, 2011 at 22:5 Comment(1)
That one works for multiple empty lines too, thanks!Silverfish
O
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

Orlantha answered 7/8, 2011 at 17:22 Comment(0)
T
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.

Tiger answered 7/8, 2011 at 17:17 Comment(0)
C
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

Cutty answered 21/6, 2013 at 11:42 Comment(1)
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.Artistic

© 2022 - 2024 — McMap. All rights reserved.