Replace new lines with a comma delimiter with Notepad++?

Notepad++Words

Notepad++ Problem Overview


I have a Notepad++ question.

How can I take the below words in Notepad++ (which is on different lines)

Apples
Apricots
Pear
Avocados
Bananas

And turn them into a paragraph with a comma at the end of each one? Like this:

Apples, Apricots, Pear, Avocados, Bananas

Notepad++ Solutions


Solution 1 - Notepad++

Open the find and replace dialog (press CTRL+H).

Then select Regular expression in the 'Search Mode' section at the bottom.

In the Find what field enter this: [\r\n]+

In the Replace with:

There is a space after the comma.

This will also replace lines like

Apples

Apricots
Pear

Avocados
Bananas

Where there are empty lines.

If your lines have trailing blank spaces you should remove those first. The simplest way to achieve this is

EDIT -> Blank Operations -> Trim Trailing Space

OR

TextFX -> TextFX Edit -> Trim trailing spaces

Be sure to set the Search Mode to "Regular expression".

Solution 2 - Notepad++

fapDaddy's answer using a macro pointed me in the right direction.

Here's precisely what worked for me.

  1. Place the cursor after the first data item. enter image description here

  2. Click 'Macro > Start Recording' in the menu. enter image description here

  3. Type this sequence: Comma, Space, Delete, End. enter image description here

  4. Click 'Macro > Stop recording' in the menu. enter image description here

  5. Click 'Macro > Run a Macro Multiple Times...' in the menu. enter image description here

  6. Click 'Run until the end of file' and click 'Run'. enter image description here

  7. Remove any trailing characters. enter image description here

  8. Done!

enter image description here

Solution 3 - Notepad++

Here's what worked for me with a similar list of strings in Notepad++ without any macros or anything else:

  1. Click Edit -> Blank Operations -> EOL to space [All the items should now be in a single line separated by a 'space']

  2. Select any 'space' and do a Replace All (by ',')

Solution 4 - Notepad++

For Notepad++ 5.9

  1. Press Ctrl+H
  2. Select Search mode Extended(\n, \r, \t, \o, \x...)
  3. Enter Find what: \r\n
  4. Enter Replace with: ,
  5. Replace_All should get the required result.

Solution 5 - Notepad++

A regex match with \s+ worked for me:

enter image description here

Solution 6 - Notepad++

Place your cursor after Apples, under Macro Tab, select Start Recording. Type the comma(,) character, space( ) character, and press End key, under Macro tab, select Stop Recording.

Ctrl+Shift+P for single playback.

Solution 7 - Notepad++

This might sound strange but you can remove next line by copying the whole text and pasting it in firefox search bar, and then re-pasting it in notepad++

step 1

step 2

Solution 8 - Notepad++

1-press CTRL F
2-paste the copied text in search bar
3-press CTRL A followed by CTRL C to copy the text again from search
4-paste in Notepad++
5-replace 'space' with ','

1-click for image
2-click for image

Solution 9 - Notepad++

You can use the command line cc.rnl ', ' of ConyEdit (a plugin) to replace new lines with the contents you want.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2231530View Question on Stackoverflow
Solution 1 - Notepad++user995502View Answer on Stackoverflow
Solution 2 - Notepad++Iain Samuel McLean ElderView Answer on Stackoverflow
Solution 3 - Notepad++trishulpaniView Answer on Stackoverflow
Solution 4 - Notepad++ketan27jView Answer on Stackoverflow
Solution 5 - Notepad++user3673View Answer on Stackoverflow
Solution 6 - Notepad++viclimView Answer on Stackoverflow
Solution 7 - Notepad++Dipin prakashView Answer on Stackoverflow
Solution 8 - Notepad++Mohsin MahmoodView Answer on Stackoverflow
Solution 9 - Notepad++DickView Answer on Stackoverflow