Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Consider the scenario where you have a specific string that you want to find-and-replace. You want to replace it with a new string that contains a newline character (or character sequence).

abc123 xyz456-blah
fsafd23 xyz456-green
89hjkf23 xyz456-red
afdsa23 xyz456-yellow
abaac123 xyz456-orange

In the scenario above, I'd like to find " xyz" and replace the space with a carriage return/newline.

The results would look like:

abc123
xyz456-blah
fsafd23
xyz456-green
89hjkf23
xyz456-red
   ︙

etc...

Question: How would you most easily achieve this using Notepad++? Are there any other tools that you'd suggest to easily perform this command?

share|improve this question

5 Answers 5

up vote 69 down vote accepted

Notepad++ will do just fine.

Search string:

 xyz
Note the space in front of xyz.

Replace string:

\r\nxyz

You will also need to set the "Search Mode" to "Extended" so that Notepad++ honors escape codes.


Some background: "\r\n" is the escape code for carriage-return, the standard for new lines in Windows. Unix-style systems use simply \n (newline). Most IDEs, Notepad++ included, will understand both styles and portray them each with new lines, but core Windows utilities do not understand \n as being equivalent to \r\n, so the latter is usually the most appropriate if the file is intended to be used in Windows environments.

share|improve this answer
1  
\r\n = Windows newline syntax. However, for everything other than plain old notepad, it will accept just \n for a newline (which is also more conventional). –  Macha Sep 2 '09 at 18:09
1  
Your phrase "more conventional" is misleading. "\r\n" is the standard on Windows. It's just that a lot of editors and IDEs happen to recognize the Unix/Linux standard line ending "\n" and display the document accordingly. There's nothing about "\n" that makes it more conventional. –  Brian Lacy Nov 12 '10 at 20:44
    
To be honest, the Win/DOS version makes more sense to me. "\r" means "Carriage Return, or 'Return the carriage/cursor to the beginning of the line'" and "\n" means "Advance the carriage/cursor forward one line". Of course, Unix came 20 years before, so I guess in that sense it is Microsoft who broke the standard. –  Brian Lacy Nov 12 '10 at 20:49
7  
this wont work unless you set the search mode, as specified in the other answer: superuser.com/questions/34451/… –  codeulike Aug 19 '11 at 15:49
1  
If you're trying to replace the literal string "\r\n" with an actual new line I had to do the following: set search mode to normal, find/replace \r\n with ***. Then set search mode to Extended, find/replace *** with \r\n. –  goku_da_master May 28 at 17:38

In Notepad++, it's very easy...

  • Find: xyz
  • Replace with: \n


  • Search Mode: Extended (\n, \t, etc)

The trick is to set the search mode.

share|improve this answer
1  
This answer worked for me, the accepted did not. Ver 5.8.6 –  bdwakefield May 19 '11 at 23:53
    
Yes same here the accepted answer did not specify using the extended mode.. –  Andy Nov 18 '11 at 8:17
    
Search Mode is key, thanks for posting. –  Jrod May 9 '12 at 17:14

In the "Replace" dialog, make sure that under Search Mode you have "Extended" selected. Then type in the find box enter "xyz" and replace with "\n".

share|improve this answer

I cheat a bit when S&Ring characters that I can't type directly into the text fields (e.g. tabs and newlines). Find somewhere in the document which already has that character, then copy it, and paste it into the replace field.

So in your example, start at the very start of one line, click, drag to the very end of the preceeding line, copy that, and paste it into the Replace dialog.

share|improve this answer
    
Care to explain why you downvoted this, random user? –  Macha Sep 2 '09 at 18:03
1  
+1 to counter random... –  ralf.w. Mar 17 '11 at 8:32

For Notepad++, change the search mode to Extended then in the Replace with field use \n.

share|improve this answer

protected by Community Jul 30 at 18:14

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.