128

I have a text file containing text like:

['22APR2012 23:10', '23APR2012 07:10', 1, 3, 0], ['22APR2012 23:10', '23APR2012 07:20', 1, 3, 0], ['22APR2012 23:15', '23APR2012 06:40', 0, 1, 0], ['22APR2012 
23:15', '23APR2012 06:40', 1, 3, 0], ['22APR2012 23:15', '23APR2012 06:40', 0, 1, 0], ['22APR2012 23:15', '23APR2012 07:00', 1, 3, 0], ['22APR2012 23:15', '23APR2012 
07:00', 0, 1, 0], ['22APR2012 23:20', '23APR2012 09:35', 0, 1, 0], ['22APR2012 23:20', '23APR2012 09:35', 1, 3, 0], ['22APR2012 23:20', '23APR2012 10:10', 1, 3, 0], 
['22APR2012 23:25', '23APR2012 05:35', 1, 3, 0], 

I want the lines break at ], characters:

['22APR2012 19:30', '23APR2012 00:25', 0, 1, 0], 
['22APR2012 19:35', '23APR2012 01:45', 1, 3, 0],
['22APR2012 19:50', '23APR2012 05:25', 1, 3, 0],
['22APR2012 19:50', '23APR2012 05:25', 0, 1, 0],
['22APR2012 19:55', '23APR2012 06:25', 1, 3, 0],

Is there a way to do it in Notepad++, or any other editor?

3
  • 2
    duplicate of Super user question:superuser.com/questions/34451/…
    – xQbert
    May 19, 2012 at 19:14
  • 1
    Can you tell me how to do this if I want to break it by ;? The solutions for ] aren't working for me Apr 15, 2013 at 2:18
  • in the accepted solution, just replace '],' with ';'
    – Aris
    Jun 24, 2014 at 9:03

6 Answers 6

216
  1. Click Ctrl + h or Search -> Replace on the top menu
  2. Under the Search Mode group, select Regular expression
  3. In the Find what text field, type ],\s*
  4. In the Replace with text field, type ],\n
  5. Click Replace All
2
  • 16
    To get this to work in Notepad++ version 6.7.8.2 I had to use the Extended Search mode, instead of Regular expression.
    – AJefferiss
    Jun 16, 2015 at 12:48
  • 6
    I also had to use Extended, however for a single line break \n was only necessary. Aug 10, 2016 at 18:16
34

Let's assume ], is the character where we wanted to break at

  1. Open notePad++
  2. Open Find window Ctrl+F
  3. Switch to Replace Tab
  4. Choose Search Mode to Extended
  5. Type ], in Find What field
  6. Type \nin Replace with field
  7. Hit Replace All
  8. Boom
2
  • 5
    6. Type \r\n in Replace with field
    – Bob Stein
    Oct 27, 2018 at 17:41
  • To be viewed in Windows (i.e. Notepad) we need \r\n. Otherwise \n works on on any other platform (should break the line and continue below it). Dec 13, 2019 at 23:01
14

Try this way. It got worked for me

  1. Open Notepad++ then copy your content
  2. Press ctrl + h
  3. Find what is should be ,(comma) or any character that you want to replace
  4. Replace with should be \n
  5. Select Search Mode -> Extended (\n, \r, \t, \0)
  6. Then Click on Replace All
1
  • #5 is key. Really, it's about an extended replacement
    – Elton
    Apr 13 at 16:58
11

If the text contains \r\n that need to be converted into new lines use the 'Extended' or 'Regular expression' modes and escape the backslash character in 'Find what':

Find what: \\r\\n

Replace with: \r\n

2

I have no idea how it can work automatically, but you can copy "], " together with new line and then use replace function.

2

If you are looking to get a comma separated string into a column with CR LF you wont be able to do that in Notepad++, assuming you didn't want to write code, you could manipulate it in Microsoft Excel.

If you copy your string to location B1:

A2 =LEFT(B1,FIND(",",B1)-1)
B2 =MID(B1,FIND(",",B1)+1,10000)

Select A2 and B2, copy the code to successive cells (by dragging):

A3 =LEFT(B2,FIND(",",B2)-1)
B3 =MID(B2,FIND(",",B2)+1,10000)

When you get #VALUE! in the last cell of column A replace it with the previous rows B value.

In the end your A column will contain the desired text. Copy and past it anywhere you wish.

1
  • 5
    "you wont be able to do that in Notepad++" - that is not true. Use reg exp as creemama exmplained above. It works perfectly.
    – mentallurg
    Jan 26, 2014 at 13:27

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