11

I am hoping to use some text editor to find all the "end of lines" in a document and replace them with just the written sequence "\n" (for ease of conversion into another file type). I've been trying with both Notepad++ and textpad with little luck.

When using regular expression mode on Notepad++ for example, I will type in [Find: \n] in the find field (which it will find successfully) and [Replace: \Q\n\E] in the replace field (the \Q and \E being verbatim search modifiers as far as I can tell), with no encouraging effects.

Is there an easy way do accomplish this replacement?

logi-kal
  • 7,107
  • 6
  • 31
  • 43
jennifer.cl
  • 205
  • 1
  • 2
  • 11

4 Answers4

30

In the notepad++ search & replace dialog (Ctrl-H), go into "Extended" mode.

From there, replacing \r\n with \\n should do it - if I understand your question correctly.

For instance, I typed in...

something
something else
blah

... and then did the above with "Replace All", which left me with:

something\nsomething else\nblah
nitsua
  • 763
  • 8
  • 20
  • Ok, awesome. I have really long rows however, so it might be better just to add the text to the ends or beginnings of lines without replacing the eols (program is saying my rows are too long), is there and easy way to do that? – jennifer.cl Mar 13 '13 at 23:12
  • If you want to keep them on different lines but still add \n to it, then you'll want to replace either `\r` or `\n` with `\\n`. Not entirely sure which you would prefer, but that should do it. – nitsua Mar 13 '13 at 23:14
  • Not sure if this would help: In the Bluefish editor you have to follow this instruction: "In the Find and Replace dialogs it is not possible to insert the keys Enter or Tab. A simple way to do it is to copy two lines in a row from the current document into the Find or Replace dialog, this way you retrieve the end of line character. The same applies for Tab." – Michael Moriarty Jan 17 '23 at 11:51
12

I know that is is a rather old question, but here's another easier method of doing the same thing if anyone else is interested.

If you go into Notepad++ and go to Edit>EOL Conversion, if allows you to convert from the current EOL to Unix-style, Windows-style, or Mac-style.

  • Unix is \n only
  • Windows is \r\n
  • Mac is \r only
6

enter image description here

Open Find and Replace -> Find "$" and Replace With "Any Character". In Search Mode Select Regular Expression. Refer Image.

Srijan Chaudhary
  • 637
  • 1
  • 8
  • 18
0

try bluefish editor http://bluefish.openoffice.nl/index.html just copy and paste, not need to worry about \r or \n