Join Lines
Turn a list into a single line with the separator you choose, or join every few lines into one.
Options
Type \t for a tab, \n for a new line and \\ for a backslash. Leave it empty to join with nothing in between.
Escaping inside double quotes puts a backslash before " and \ (say "hi" becomes "say \"hi\""). Single quotes are doubled the SQL way (O'Brien becomes 'O''Brien'), and so are backticks. JSON string always encodes with JSON.stringify; CSV quoting adds quotes only to items with a comma, quote, line break or the separator. Custom never escapes.
Blank or 0 makes one line. 2 joins lines in pairs.
Each output line only differs when you join every N lines.
Joined text
How to join lines
Paste your list into Your lines, one item per line, or press Load example. The
joined text appears next to it and updates as you type. Pick a separator with the quick buttons or type your own:
\t is a tab, \n a new line and \\ a backslash. Copy the result or download it
as a .txt file. Everything runs in your browser, so nothing you paste is uploaded.
- Wrap each item puts double quotes, single quotes, backticks or your own text around every item. Escape quotes inside items stops those quotes from breaking the result.
- Start with and End with add text around the result, such as brackets.
- Join every N lines makes one output line from every N input lines instead of one line from everything.
- Clean-up trims spaces, skips empty lines and removes duplicates before joining.
Turn a column into a comma-separated list
When you copy a column from Excel, Google Sheets or a database client, each cell arrives as its own line. Paste it
here and the default settings give you value1, value2, value3. Trimming removes the stray spaces that
spreadsheet cells often carry, and skipping empty lines drops blank cells, so you don't get doubled commas. Choose
Comma instead of Comma and space when the list goes into a URL parameter, a config
file or a tag field that expects no spaces.
Build SQL IN lists and JSON arrays safely
A quote inside an item ends the string early. Wrap O'Brien in single quotes without escaping and you get
'O'Brien': SQL reads the string 'O' followed by stray text, and the query fails. The
SQL IN list preset doubles single quotes, which is the standard SQL escape:
SELECT * FROM users WHERE last_name IN ('O''Brien', 'Smith');
Use this for queries you run by hand. In application code, pass values as query parameters instead of building SQL
strings. Two database quirks are worth knowing. MySQL also treats a backslash as an escape character by default, so
items that contain backslashes need them doubled. Oracle accepts at most 1,000 values in one IN list: set
Join every N lines to 1000 and Add start and end to each output line, then combine
the lists with OR.
The JSON array preset encodes every item with JSON.stringify, which escapes double
quotes, backslashes and control characters such as tabs, so the result always parses. Hand-made quoting usually
misses the backslash: C:\temp has to be written "C:\\temp". Every item becomes a string,
so 42 turns into "42". For an array of numbers, choose None and
Comma, and start and end with [ and ].
The CSV row preset follows RFC 4180: an item is quoted only when it contains a comma, a double quote or a line break (or your separator, if you changed it), and quotes inside it are doubled.
Join lines in pairs or groups
Some exports put related values on consecutive lines, such as a label and then its value, or a keyword and then its search volume. Set Join every N lines to 2 to rebuild the pairs: lines 1 and 2 become the first output line, lines 3 and 4 the second, and so on. If the count doesn't divide evenly, the last line holds what is left over. Empty lines are skipped before grouping, so a stray blank line doesn't shift every pair after it. Turn off Skip empty lines if blank lines are part of the data.
Examples
| Input | Settings | Output |
|---|---|---|
| red green blue | Default: comma and space | red, green, blue |
| O'Brien Smith | SQL IN list | ('O''Brien', 'Smith') |
| say "hi" C:\temp | JSON array | ["say \"hi\"","C:\\temp"] |
| Acme, Inc. Globex | CSV row | "Acme, Inc.",Globex |
| id email created_at | Backticks, comma and space | `id`, `email`, `created_at` |
| Name Ada Role Engineer | Separator ": ", join every 2 lines | Name: Ada Role: Engineer |
Join lines in Excel, Google Sheets or the terminal
- Excel (2019 or later, and Microsoft 365):
=TEXTJOIN(", ", TRUE, A2:A100). TheTRUEskips empty cells. If the result is longer than 32,767 characters, the most a cell can hold, TEXTJOIN returns#VALUE!. - Google Sheets: the same TEXTJOIN formula works.
=JOIN(", ", A2:A100)is shorter but has no option to skip empty cells. - Command line:
paste -sd, file.txtjoins every line of the file with commas.-smerges the lines of each file into one line and-dsets the delimiter. The delimiter list is used one character at a time, so-d ', 'alternates a comma and a space instead of putting both between items.paste -d, - - < file.txtjoins lines in pairs, andtr '\n' ','works too but leaves a comma at the end.
Limits and edge cases
- Lines can end in \n, \r\n or \r. One line break at the end of the input doesn't create an empty item.
-
Remove duplicates keeps the first copy and is case-sensitive, so
Appleandappleboth stay. - The page handles 100,000 lines without trouble. Above about 2 million characters, live updates pause and you press Join lines to update the result.
- To go the other way and break a joined list back into lines, use Split Text by Delimiter. To add text to every line without joining them, use Add Prefix & Suffix.
Frequently asked questions
How do I convert a list into a comma-separated string?
Paste the list with one item per line and keep the default separator, a comma followed by a space. Pick Comma if you don't want the spaces, then copy the single line from the result box.
How do I make a SQL IN clause from a list of values?
Paste the values and press the SQL IN list preset. Each value goes in single quotes, any single quote inside a value is doubled, and the whole list is wrapped in parentheses, ready to paste after IN.
How do I join every two lines into one?
Enter 2 in Join every N lines. Lines 1 and 2 become one line, lines 3 and 4 the next, and so on. The separator controls what goes between the two parts.
How do I put quotes around each item?
Choose Double quotes, Single quotes or Backticks under Wrap each item, or Custom to type your own text before and after. Keep Escape quotes inside items on so an item that contains the same quote doesn't break the result.
How do I join lines with a tab or a line break between them?
Press Tab or New line, or type \t or \n in the separator field. They are turned into a real tab or line break, and \\ gives a single backslash.
Is my list uploaded anywhere?
No. Joining happens in your browser and nothing is sent to a server. If the list is under 200 KB, it is kept in your browser's local storage so it is still there when you come back.