LTLine Toolkit

Tools / Add quotes around each line

Add Quotes Around Each Line

Wrap every line in quotes in one pass. Characters inside the line are escaped, so the output is ready for a SQL IN list, a CSV field or a code array.

Everything runs in your browser. Your text is never uploaded or stored.

How it works

Quoting a list is usually the last step before you paste it into something that expects strings. A WHERE city IN (...) clause needs 'Kathmandu', not Kathmandu. A CSV field that contains a comma needs double quotes around the whole value. A JavaScript array of names needs quoted strings. Doing that by hand for 200 rows is where mistakes happen.

This tool reads your text one line at a time, wraps each line in the quote character you pick, and escapes any quote of the same kind that already appears inside the line. A line containing O'Brien becomes 'O\'Brien' when you use single quotes, which is what most SQL dialects expect. With double quotes it becomes "O'Brien" and needs no escaping at all.

Edge cases

Do it in code instead

The same result with a shell one-liner or a few lines of Python, if you would rather automate it:

Bash (sed, double quotes)

sed 's/^/\"/; s/$/\"/' list.txt

Bash (awk, single quotes)

awk '{ printf "\047%s\047\\n", $0 }' list.txt

Python

lines = open('list.txt').read().splitlines()
print('\n'.join("'" + l.replace("'", "\\'") + "'" for l in lines))

JavaScript

const out = text.split('\n').map(l => JSON.stringify(l)).join('\n');

Excel

="""&A1&"""

Questions

Does it escape quotes inside the line?
Yes. If you choose single quotes, an apostrophe in the line is escaped with a backslash. If you choose double quotes, double quotes are escaped. This keeps the output syntactically valid for most SQL engines and for JavaScript string literals.
Can I use it for a SQL IN list?
Yes. Choose single quotes, then use the “add comma to end of each line” tool and delete the final comma. For MySQL, PostgreSQL and SQLite a backslash-escaped apostrophe is accepted, but the standard SQL way is doubling it, so check your dialect if the text contains many apostrophes.
Why do blank lines stay blank?
Because an empty CSV cell and a missing row are different things. Blank lines are skipped by default; untick “skip blank lines” if you want an explicit empty quoted string.

Last verified: 2026-12-04