Replace new line with comma in Sublime Text Editor

If you have a file or a string that you want to replace every new line with a comma follow the below steps,

  1. Open the file in Sublime Text Editor,

    Example file with multiple lines

    This is my Line 1
    This is my Line 2
    This is my Line 3
    This is my Line 4
    This is my Line 5
  2. Now press Control + H (or Command + H on macOS),
  3. Make sure you select .* button to enable RegEx,
  4. Now in Find: add \n (if windows encoding file) \r\n (if mac encoding)
  5. Add Replace: as "," (without the quotes).
  6. Click on REPLACE ALL! Thats it!


This is my Line 1,This is my Line 2,This is my Line 3,This is my Line 4,This is my Line 5

⛏️ Note: If you want to a space after each comma, just add a space after the comma ", " in Replace.

Let's me give you a gif demo to make it easy to follow,

How to replace new line with comma in Sublime Text
How to replace new line with comma in Sublime Text

Recent Posts:

Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.