How to remove two newlines in a plain text document quicky?

Hi all,

So my hard disk crashed and I have to recover some code I was doing from a FTP server. Strangely, when I open up the file, the newlines seem to be mangled so that instead of a single new line, I get double new lines, like this:



private $a = 0;
private $b =0;


The code is about a thousand lines long - I think if I am going to manually remove the double padding it would take forever. It’s not just for aesthetics though; it seems that on the server those newlines are not there and I have been getting syntax errors at blank lines (ouch).

Any tool I could use which allow me to see newline characters (so I can remove the unnecessary ones with a search/replace) or otherwise remove ALL newlines (so I can just use eclipse to reformat it)

Thanks in advance!

In a nice, simple text editor like Notetab Light (freebies), you can replace all occurrences of ^p^p with ^p, and take care of it.

Are you seeing the 2 new lines on a UNIX or Linux system? If so use the command:

Make a copy of the file first in case I have misdiagnosed the issue.

dos2unix <filename>

I’m seeing it on Windows. Sorry that I’ve forgotten to specify that.

Since yuo’re a dev, I’d suggest you open the file in a hex editor first to be sure you understand what you’ve really got. Are we seeing 0x0A, 0x0A, 0x0D, or 0x0A, 0x0D, 0x0A, 0x0D or what. Mightmake the weirdness make more sense. it’ll also help you know what to replace with what to get to where you want to go.

Cool suggestion. What I get is this

0x0D 0x0D 0x0A

Somehow I got both Unix and Windows newline mixed in together.

Edit: Any idea how to proceed next? I cannot just erase all the 0x0D 0x0D 0x0A like I thought as this would cause some code to be on the same line as comments.

Edit2: Doh, never mind, I just need to replace the search pattern “0x0d 0x0D 0x0A” with “0x0D 0x0A”. Thanks all!

My normal fix is dos2unix as mentioned above. But I thought I’d explain the likely cause for this. When you FTPd the file either the ftp tool was set into ASCII mode, or it looked at the file extension and decided it was ASCII. On a wide variety of systems this will munge the CR to be a CR/LF pair.

t.