On Linux, the basic command is sed 's/^/"/; s/$/"' input.txt > output.txt. It wraps every line in double quotes and sends the result to a separate file, leaving input.txt unchanged.
That command treats quotes as literal wrappers, which is enough for a plain list. It is not enough for JSON, SQL, or CSV when a value contains its own quote character. Those formats escape embedded quotes differently, so the target format—not the shell command—is the first decision.

Choose the target format before adding quotes
Compare the output you need with the rules that will consume it. The following table describes the format-specific behavior built into Add Quotes to Each Line.
| Target | Typical wrapper | Embedded quote handling | Common use |
|---|---|---|---|
| Plain quoted lines | Double quotes | No format-specific escaping | Text formatting or manual editing |
| JSON array items | Double quotes | Backslashes double and double quotes are backslash-escaped | JSON fixtures, configuration, and test data |
| SQL string values | Single quotes | An embedded apostrophe becomes two apostrophes | SQL WHERE ... IN lists |
| CSV fields | Double quotes | An embedded double quote becomes two double quotes | CSV rows and spreadsheet imports |
| JavaScript template literals | Backticks | Backticks and the interpolation opener are escaped | JavaScript source |
These rules are not interchangeable. RFC 8259 governs JSON string escaping, while RFC 4180 specifies that an embedded double quote in a CSV field is doubled. The SQL rule used by PostgreSQL, SQLite, and the ISO standard is also different: an embedded apostrophe is represented by two apostrophes rather than a backslash. PostgreSQL’s lexical documentation describes that string-constant convention.
Plain double quotes are only visual wrappers, not shell-safe serialization. Adding double quotes around a line in Bash does not neutralize characters such as $, backticks, or command substitutions. Use this process to prepare structured data for JSON, SQL, CSV, or an editor—not to make untrusted shell fragments executable.
Add quotes to each line in Linux
Write the result to a different file for the first run. This makes it easy to compare the original and transformed text before replacing anything.
- Inspect the source and confirm that it contains one item per line by running cat -n input.txt.
- Create a backup with cp input.txt input.txt.bak.
- Wrap every line in double quotes by running sed 's/^/"/; s/$/"' input.txt > output.txt.
- Review the result with cat -n output.txt, or compare both files with diff -u input.txt output.txt.
- After confirming the output, replace the original when appropriate with mv output.txt input.txt.
The single quotes around the sed script are deliberate: they keep the shell from interpreting the double quotes inside the script. The first substitution matches the start of each line, while the second matches its end.
- The basic command turns a blank line into "". To remove blank and whitespace-only lines before wrapping, run sed '/^[[:space:]]*$/d; s/^/"/; s/$/"/' input.txt > output.txt.
- To use single-quote wrappers, run sed "s/^/'/; s/\$/'/" input.txt > output.txt. This adds characters but does not escape apostrophes already inside a line.
- To add a comma between every pair of quoted lines while leaving the final line clean, run sed 's/^/"/; s/$/"/; $!s/$/,/' input.txt > output.txt.
- On GNU sed, sed -i.bak 's/^/"/; s/$/"/' input.txt edits the file in place and keeps a backup named input.txt.bak. In-place option syntax differs on BSD systems.
Build JSON, SQL IN, and CSV output
The basic sed command applies characters uniformly. When the result must be valid in a specific syntax, use a route that applies that syntax’s escaping rules.
Create a JSON array
For a JSON array, Python’s standard JSON serializer is more dependable than manually chaining several substitutions:
python3 -c 'import json,sys; print(json.dumps([line.rstrip("\r\n") for line in sys.stdin], ensure_ascii=False))' < input.txt > values.json
Each physical input line becomes one JSON string. The serializer encodes embedded double quotes, backslashes, and control characters, then adds the array brackets and valid separators. A blank line becomes an empty string, so remove placeholder blank lines first if they should not appear as values.
Create an SQL IN list
For the standard SQL string-literal rule, double embedded apostrophes, wrap every value in single quotes, and place the values inside an IN expression:
{ printf "IN ("; sed "s/'/''/g; s/^/'/; s/\$/'/; s/\$/,/; \$s/,$//" input.txt; printf ")\n"; } > values.sql
The first sed expression doubles apostrophes in the source values. The remaining expressions add the wrappers and commas without leaving a trailing comma. For application code, parameterized queries are preferable when input can be untrusted; this command creates literal SQL text.
Create a CSV row
For one CSV row, double embedded double quotes, wrap every field, and separate the fields with commas:
sed 's/"/""/g; s/^/"/; s/$/"/' input.txt | paste -s -d, - > row.csv
Because each field is quoted, a comma already inside a value remains part of that field. The one-item-per-line workflow cannot represent a field containing a literal line break; split or transform such data before constructing the row.
Use a format-aware browser workflow
When switching between formats or handling values with embedded quotes, Add Quotes to Each Line applies the selected format’s published escaping rule instead of requiring separate shell expressions.
- Paste the original list into the input area, with one item on each line.
- Select the preset for JSON array, SQL IN clause, CSV row, plain quotes, or another available quote style.
- Adjust the quote style, delimiter, trailing delimiter, escaping, blank-line skipping, or per-line trimming as needed.
- Copy the generated result and paste it into the editor, query console, or spreadsheet import where it belongs.
The trailing delimiter is off by default, which prevents a JSON array or SQL IN list from ending with an unwanted comma. Enable it only when the destination requires one. The result also reports how many lines were processed. For JavaScript, the backtick style escapes both backticks and the ${ interpolation opener, so pasted content cannot introduce a template expression.
Processing happens in the browser: the pasted data is not uploaded, stored, or attached to an account. Input is limited to one million characters. For a larger local file or a streaming pipeline, keep using sed, Python, or another local command instead.
One important behavior is intentional: running the tool on its own output wraps that output again. The tool cannot determine whether existing quotes are content or previous wrapping. If you need different settings, start again from the original list.
Check the result before pasting
- Confirm the target syntax. A JSON array, SQL IN clause, and CSV row use different quoting and escaping rules even when their visible wrappers look similar.
- Inspect embedded quotes. A generic wrapper can produce invalid output when the original value already contains the target delimiter.
- Check the final delimiter. The standard presets leave the last item clean by default; enable a trailing delimiter only when required.
- Decide how blank lines should behave. A basic sed command includes them, while the browser tool can skip them explicitly.
- Check surrounding spaces. Per-line trimming is available in the browser tool but should be enabled only when leading or trailing whitespace is not meaningful.
- Use the original list for another run. Feeding formatted output back into the tool can produce a second layer of quotes.
In short, sed is the direct Linux answer when literal wrapping is all you need. Use format-specific escaping or the browser tool when the output must remain valid JSON, SQL, or CSV after values are pasted into another system.
If you're weighing options, Character Counter Command Line vs Online: Which to Use? covers this in detail.
If you're weighing options, Is Text Sorter Safe to Use Online? Privacy Explained covers this in detail.