Add Prefix and Suffix to Each Line
Type a prefix, a suffix or both, paste your list, and every line comes back with that text added at its start and end. Empty lines are left alone unless you say otherwise.
0 words 0 characters 0 lines
Continue with this text: Make a comma listAdd line numbersSort lines
Your text stays in your browser: nothing is uploaded or stored on a server.
How to use it
- Paste your list into Your text, one item per line, or press Open file to load a .txt or .csv file. Example fills in a short shopping list.
- Type the prefix in Prefix (start of each line). It starts as
-(a hyphen and a space), which turns lines into a Markdown bullet list. - Type the suffix in Suffix (end of each line), or leave it empty.
- Set the checkboxes: Read \t as a tab, \n as a line break and \\ as one backslash (on by default), Skip empty lines (on by default) and Trim spaces first (off by default).
- The Result box updates as you type. Press Copy, Download .txt, or Use as input to keep working on the result with another tool.
Both fields are optional: fill in only the prefix to add text at the start of each line, only the suffix to add text at the end, or both to wrap each line.
What each option does
| Option | Default | What it changes |
|---|---|---|
| Prefix (start of each line) | - |
Text put before every line, exactly as typed, spaces included. |
| Suffix (end of each line) | empty | Text put after every line, exactly as typed. |
| Read \t as a tab, \n as a line break and \\ as one backslash | on | Turns the escape codes in both fields into the characters they stand for (see below). Off: both fields are used exactly as typed. |
| Skip empty lines | on | Lines that are empty or contain only spaces or tabs are passed through untouched. Off: they get the prefix and suffix too. |
| Trim spaces first | off | Removes spaces and tabs from the start and end of each line before adding the prefix and suffix. The prefix and suffix themselves are never trimmed. |
With the escape checkbox ticked, the two fields understand three escape codes: \t becomes a tab, \n becomes a line break and \\ becomes one backslash. Any other backslash stays as typed. A suffix of \n therefore puts an empty line after every item, and a prefix of \t indents every line by one tab.
The rules, exactly
- A line is whatever sits between line breaks. Windows (
\r\n), old Mac (\r) and Unix (\n) line endings are all recognized, and the result always uses\n. - Nothing inside the line changes. The tool does not escape quotes, HTML characters or backslashes that are already in your text.
O'Brienwith prefix'and suffix',becomes'O'Brien',, which breaks an SQL string; in SQL a single quote inside a string is written as two single quotes ('O''Brien'), so double the apostrophes first with replace text. - A trailing line break counts as one more line. If your text ends with a line break, the last “line” is empty. With Skip empty lines on it stays empty and the result also ends with a line break; with it off you get one extra line holding only the prefix and suffix, such as
<li></li>. - Whitespace-only lines are treated as empty when skipping, and they keep their spaces even if Trim spaces first is on.
- Accents, emoji and any script pass through unchanged:
café 👍🏽with[and]becomes[café 👍🏽]. - Backslashes in the fields: with the escape checkbox ticked, a prefix such as
C:\temp\comes out asC:, a tab andemp\, because\tis read as a tab. TypeC:\\temp\\instead (each\\gives one backslash, and\\tgives a literal\t), or untick the checkbox soC:\temp\is used exactly as typed.
Worked examples
The default settings on the built-in example (prefix - , Skip empty lines on):
apples - apples
bread - bread
milk → - milk
coffee - coffee
The same text with Skip empty lines off gives - alone on the fourth line.
| Before | Prefix | Suffix | After |
|---|---|---|---|
1001 |
' |
', |
'1001', |
SKU-1 |
" |
", |
"SKU-1", |
Buy milk |
- [ ] |
- [ ] Buy milk |
|
example.com/page |
https:// |
https://example.com/page |
|
alpha |
; |
alpha; |
|
alpha |
\tyes |
alpha + tab + yes |
|
␣␣apples␣ (trim on) |
' |
', |
'apples', |
␣␣apples␣ (trim off) |
' |
', |
'␣␣apples␣', |
(␣ marks a space.) For HTML, a prefix of <li> and a suffix of </li> turns each line into a list item; put the <ul> and </ul> lines around the result yourself.
When people use it
- SQL
INlists. Paste a column of IDs from a spreadsheet, add'and',, then remove the comma after the last value and wrap the lot in parentheses. The comma separator does the whole job in one step: it quotes, joins and adds the( ). - Code and config. Turn a list into array items (
"and",), add;to the end of statements, comment out lines with#or//, or indent a block with\t. - Markdown and checklists.
-for bullets,- [ ]for task lists,>for quoted lines. For numbered lists, use add line numbers, which counts for you. - URLs and file names. Add
https://to bare domains, a folder path to file names, or a file extension such as.jpgas the suffix. - Tags and keywords. Add
#in front of each word for hashtags, or wrap keywords in[]for exact-match lists in ad tools.
Compared with doing it in a spreadsheet or editor
In Excel you can join text with the ampersand operator, so ="'"&A1&"'," in a new column and filled down gives the same result as prefix ' and suffix ',. In a code editor with regular-expression search, replacing ^ adds text at the start of each line and replacing $ adds it at the end. Both work, but they need a formula or an expression and a few more steps to copy the result back out; here you type the two pieces of text and copy.
If the list needs cleaning first, run it through remove empty lines, remove duplicate lines or sort lines, then open this tool again: the cleaned text comes with you, because text is carried between tools in the same browser tab.
Questions
How do I add text to the beginning of each line?
Type the text in Prefix (start of each line) and leave the suffix empty. The prefix is added exactly as typed, so include a trailing space if you want one, as in the default "- ".
How do I add a comma to the end of each line?
Clear the prefix and type a comma in Suffix (end of each line). Every line gets the comma, including the last one. If you need a single line such as a, b, c with no trailing comma, use the comma separator instead.
How do I wrap each line in quotes?
Type the quote mark in both fields, for example " as prefix and " as suffix, or ' and ', for a list of SQL values. Quotes already inside a line are not escaped, so a name such as O'Brien needs its apostrophe doubled first.
Can I add a tab or a line break?
Yes. Type \t in either field for a tab and \n for a line break; this works while Read \t as a tab, \n as a line break and \\ as one backslash is ticked (the default). For a literal backslash, type \\ (so C:\\temp\\ gives C:\temp\), or untick the box to use both fields exactly as typed.
What happens to empty lines?
With Skip empty lines ticked (the default), empty lines and lines that contain only spaces are returned unchanged, so paragraph gaps stay where they were. Untick it to add the prefix and suffix to those lines as well. To delete them, use remove empty lines first.
Is my list uploaded anywhere?
No. The text is processed in your browser and kept only in this tab, so it can be passed to another tool; it is gone when you close the tab.
Is this a replacement for sed, Notepad++ or an Excel formula?
For one-off jobs, yes. It does the same thing as a regular-expression replace of ^ or $ in an editor or a ="'"&A1&"'," formula in Excel, without writing the expression or filling a column.