How to Replace New Lines With Commas (and Comma Separated to New Lines)
· 5 minutes read

You copied a column from a spreadsheet and need it as a, b, c for an e-mail, a tag field or an SQL IN (...) clause. Or the opposite: someone sent you a long comma separated list and you need one item per line. Both are separator conversions, and here is how to do them quickly.
The fastest way: online separator converter
- Open the separator converter.
- Paste your list.
- Click a preset: new lines → comma, comma → new lines, spaces → new lines or new lines → spaces. For anything else, pick the input separator in From and the output in To (commas, semicolons, spaces, tabs, pipes or your own).
- Adjust the options and copy the result.
The options handle the annoying details:
- Trim items removes spaces around items, so
red , greenbecomesredandgreen. - Remove empty items drops blank lines and double commas.
- Space after comma chooses between
a, b, c(readable) anda,b,c(CSV, code). - Wrap in quotes produces
'a', 'b', 'c'for SQL or"a","b","c"for CSV and JSON; quotes inside values are doubled.
SK01
SK02 → 'SK01', 'SK02', 'SK03'
SK03
Excel
Lines → comma separated: TEXTJOIN (Excel 2019 and Microsoft 365) joins a range with any separator and can skip empty cells:
=TEXTJOIN(", ", TRUE, A1:A100)
With quotes for SQL: ="'" & TEXTJOIN("', '", TRUE, A1:A100) & "'".
Comma separated → rows: in Microsoft 365 use =TEXTSPLIT(A1, , ",") – the empty second argument means "don't split into columns", the third splits into rows. Add TRIM: =TRIM(TEXTSPLIT(A1, , ",")). In older versions use Data → Text to Columns → Delimited → Comma, then copy the row and Paste Special → Transpose.
A cell that contains line breaks (Alt+Enter) can be converted with =SUBSTITUTE(A1, CHAR(10), ", ").
Google Sheets
=TEXTJOIN(", ", TRUE, A1:A100) lines → commas
=TRANSPOSE(SPLIT(A1, ",")) commas → rows
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(A1, ",")))) with trimming
=SUBSTITUTE(A1, CHAR(10), ", ") line breaks inside a cell → commas
SPLIT ignores empty items by default; set its fourth argument to FALSE to keep them.
Notepad++
Open Search → Replace (Ctrl+H):
- New lines → commas: set Search Mode to Extended, find
\r\n(Windows files) or\n(Unix files), replace with,. - Commas → new lines: Extended mode, find
,and replace with\r\n. To also remove the spaces after the commas, switch to Regular expression, find\s*,\s*and replace with\r\n.
You can check the line ending type in the status bar (Windows (CR LF) / Unix (LF)).
VS Code
Open Find and Replace (Ctrl+H), enable regular expressions (.*), then:
- New lines → commas: find
\n, replace with,. - Commas → new lines: find
,\s*, replace with\n.
VS Code handles \r\n for you when you search for \n.
Command line
paste -sd, input.txt # lines → a,b,c
paste -sd, input.txt | sed 's/,/, /g' # lines → a, b, c
tr ',' '\n' < list.txt # commas → lines
tr -s ' ' '\n' < words.txt # spaces → lines (squeezes repeated spaces)
tr '\n' ' ' < input.txt # lines → spaces
tr '\n' ',' also works for lines → commas, but leaves a trailing comma because the file ends with a newline – paste -sd, does not. On Windows PowerShell: (Get-Content input.txt) -join ', ' and (Get-Content list.txt) -split ',\s*'.
Common pitfalls
- Trailing separator.
a, b, c,breaks SQL and JSON. Remove empty items (the tool does by default) or usepaste -sd,. - Hidden
\rcharacters. Lists from Windows end lines with\r\n; replacing only\nleaves invisible\rcharacters inside your items. Our tool normalises line endings automatically. - Commas inside values. "Bratislava, Slovakia" will be split in two when converting commas → lines. Use a different separator (semicolon, tab) or wrap such values in quotes before converting.
- Double spaces. Splitting on single spaces creates empty items from double spaces. The spaces option splits on any run of whitespace.
FAQ
How do I replace new lines with commas online?
Paste the list into the separator converter and click new lines → comma. Tick Space after comma for a, b, c.
How do I convert a comma separated list to new lines?
Use the comma → new lines preset. Spaces after the commas are trimmed automatically.
How do I make a list for an SQL IN clause?
Choose new lines → comma with single quotes, then wrap the result in IN ( … ). Alternatively, keep one value per line with the add prefix and suffix tool and its 'x' preset.
Is my data uploaded?
No. The conversion runs entirely in your browser.