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

**URL:** <https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777>\
**Category:** Factual Questions\
**Created:** [June 5, 2009, 3:33am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777 "2009-06-05T03:33:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [June 5, 2009, 3:33am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/1 "2009-06-05T03:33:12Z")

</div>

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:

```auto

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!

---

<div class="post-metadata">

**Author:** ![Early\_Out](https://avatars.discourse-cdn.com/v4/letter/e/6f9a4e/32.png) [@Early\_Out](https://boards.straightdope.com/u/Early_Out)\
**Post date:** [June 5, 2009, 3:40am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/2 "2009-06-05T03:40:00Z")

</div>

In a nice, simple text editor like [Notetab Light](http://www.notetab.com) (freebies), you can replace all occurrences of ^p^p with ^p, and take care of it.

---

<div class="post-metadata">

**Author:** ![gazpacho](https://avatars.discourse-cdn.com/v4/letter/g/6f9a4e/32.png) [@gazpacho](https://boards.straightdope.com/u/gazpacho)\
**Post date:** [June 5, 2009, 3:40am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/3 "2009-06-05T03:40:57Z")

</div>

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\>

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [June 5, 2009, 3:46am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/4 "2009-06-05T03:46:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [June 5, 2009, 4:22am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/5 "2009-06-05T04:22:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [June 5, 2009, 5:46am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/6 "2009-06-05T05:46:51Z")

</div>

> [@LSLGuy](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [June 5, 2009, 5:54am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/7 "2009-06-05T05:54:27Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![PuddingCat](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@PuddingCat](https://boards.straightdope.com/u/PuddingCat)\
**Post date:** [June 5, 2009, 10:45am UTC](https://boards.straightdope.com/t/how-to-remove-two-newlines-in-a-plain-text-document-quicky/498777/8 "2009-06-05T10:45:19Z")

</div>

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.
