Add Prefix and Suffix to Lines

Put the same text before or after every line of a list, or insert it at any column.

If you use {line}, the line appears only where you put it, so <li>{line}</li> in Prefix is a complete template.

Quick templates:

Placeholders: {n} is the line number and {line} is the line itself. Type \t for a tab and \n for a new line.

Digits: 3 gives 001. Use 0 for no padding.
Updates as you type. Ctrl + Enter also works.

How to add text to the start or end of every line

Paste your list into Your lines, one item per line. Type what should go before each line in Prefix and what should go after it in Suffix. You can fill one field or both. The result updates as you type, and you can copy it or download it as a .txt file. The quick templates fill both fields for common jobs, such as quoting every line or building an HTML list. Everything runs in your browser, so nothing you paste is uploaded.

What the options do

  • Skip empty lines (on by default) leaves blank lines, including lines that only contain spaces, as they are. They get no prefix or suffix and no number, so a list with gaps keeps its gaps and the numbering still runs 1, 2, 3.
  • Trim lines first removes spaces and tabs at both ends of each line before adding text. Turn it on for lists copied from documents, emails or spreadsheets.
  • Remove duplicate lines keeps the first copy of each line and drops the repeats before anything is numbered. The comparison is exact and case-sensitive, and it happens after trimming when trimming is on. Empty lines are never removed.
  • Start numbers at and Zero-pad numbers to control the {n} placeholder. Starting at 0 gives zero-based numbering, and a width of 3 turns 7 into 007.

Examples

TaskLinePrefixSuffixResult
URLs from slugs blog/pricing https://example.com/ https://example.com/blog/pricing
SQL rows Ada (' '), ('Ada'),
Quoted strings apple " ", "apple",
Numbered list Buy milk {n}. 1. Buy milk
HTML list Home <li> </li> <li>Home</li>
File names report-q3 exports/ .csv exports/report-q3.csv

For the SQL rows, paste the result after INSERT INTO people (name) VALUES and delete the comma after the last row. The same trick builds a list for WHERE id IN (...), a JavaScript array or a block of redirect rules.

Placeholders: {n} and {line}

{n} is replaced with the line number. It counts only the lines that get text, so skipped empty lines and removed duplicates don't use up a number. {line} is replaced with the line itself, after trimming if that option is on.

As soon as {line} appears in the prefix or the suffix, the tool stops adding the line between them and puts it only where the placeholder is. That makes a single field work as a template: <li>{line}</li> in Prefix gives the same result as <li> and </li> in the two fields, and <a href="/{line}">{line}</a> uses the line twice. Placeholders that appear in your pasted text are left alone.

You can also type \t for a tab, \n for a new line and \\ for a backslash. A suffix of \n puts a blank line after every item.

Inserting a column into CSV-like lines

Choose Insert as a column when each line is a row of fields, as in CSV, TSV or pipe-separated data. Enter the text, the column number and the delimiter, or use the Comma, Tab, Pipe and Semicolon buttons. Column 1 puts the text before the first field and column 3 puts it between the second and third fields. A number past the last field adds the text at the end of the line, and the tool tells you how many lines were too short. With {n} as the text and column 1, Ada,London becomes 1,Ada,London, which is a quick way to add an ID column.

The split is plain text: a delimiter inside quotes, as in "London, UK", still counts as a field boundary, and a header row gets the new text like any other line. To pull columns out of delimited lines instead, use Split Text.

How to do it in Excel, Google Sheets or sed

In Excel or Google Sheets, with your values in column A, type ="prefix"&A1&"suffix" in B1 and fill it down. To wrap a value in double quotes, write each quote as two inside a string: =""""&A1&"""". In Google Sheets, =ARRAYFORMULA(IF(A1:A="", "", "https://example.com/"&A1:A)) fills the whole column at once and leaves empty rows empty.

On the command line, sed 's/^/prefix/' list.txt adds text to the start of every line and sed 's/$/suffix/' list.txt adds it to the end. sed 's/.*/"&",/' list.txt does both and gives "apple",, because & stands for the whole line. If your text contains slashes, pick another delimiter, as in sed 's|^|https://example.com/|', and escape any & or backslash you want literally. For numbering, awk '{print NR ". " $0}' list.txt works. On files with Windows (CRLF) line endings, GNU sed keeps the carriage return as part of the line, so a suffix lands after it; convert the file with dos2unix first. This tool accepts any line ending and writes Unix (\n) endings.

Edge cases and limits

  • Quotes inside your lines are not escaped. O'Brien with the SQL template becomes ('O'Brien'),, which breaks the query, so double the quote first (O''Brien).
  • The suffix goes on every line, including the last. If you need a separator between items but not after the last one, or everything on one line, use Join Lines.
  • A single line break at the very end of the input is ignored, so it doesn't create an extra empty line.
  • The tool handles lists of 100,000 lines. Above about 2 MB of text, live updates turn off and the Add text button updates the result.

Frequently asked questions

How do I add text to the beginning of every line?

Paste your list, type the text in the Prefix field and copy the result. Every line gets the prefix, and empty lines are left alone unless you turn off Skip empty lines.

How do I add a comma or quotes to the end of each line?

Type a comma in the Suffix field, or use the Quote each line template and add a comma after the closing quote in the suffix. If you want commas between items but not after the last one, Join Lines is the better fit.

How do I number each line?

Put {n} in the prefix, for example "{n}. " for a numbered list. Set the starting number, and a zero-pad width of 3 to get 001, 002 and so on. Skipped empty lines are not counted.

How do I add a prefix to every cell in Excel or Google Sheets?

In the next column, use a formula such as ="prefix"&A1&"suffix" and fill it down. You can also paste the column here, add the text, and paste the result back into the sheet.

Can I add a column to a CSV file?

Yes. Choose Insert as a column, set the delimiter and the column number, and type the text to insert, for example {n} for an ID column. Quoted fields that contain the delimiter are split like any other text, so check those rows.

Is my text uploaded anywhere?

No. The tool runs in your browser and nothing you paste is sent to a server. Input under 200 KB is kept in your browser's local storage so it is still there when you come back.