You have a list of 200 product slugs and need full URLs. Or a column of names that must become SQL values in quotes and brackets. Or a set of keywords that each need square brackets for exact match in an ad campaign. The job is the same every time: put the same text before, after or around every line, without touching the line in between.
This guide shows the everyday situations where prefixes and suffixes save time, the patterns worth knowing, and how to apply them in a browser tool, a spreadsheet, a code editor or the command line.
Common patterns
Most jobs fall into a handful of patterns. Here is what a line such as red running shoes becomes with each one:
| Goal | Prefix | Suffix | Result |
|---|---|---|---|
| Full URL | https://example.com/search?q= |
https://example.com/search?q=red running shoes |
|
| CSV / JSON string | " |
", |
"red running shoes", |
| SQL row | (' |
'), |
('red running shoes'), |
| HTML list item | <li> |
</li> |
<li>red running shoes</li> |
| Markdown task | - [ ] |
- [ ] red running shoes |
|
| Exact match keyword | [ |
] |
[red running shoes] |
| Phrase match keyword | " |
" |
"red running shoes" |
| File name | img- |
.jpg |
img-red running shoes.jpg |
Notice that the URL example keeps the spaces. If a line will become part of a URL, it usually needs encoding afterwards so spaces become %20 or +; the URL Encoder handles that, and our guide on URL encoding explains why.
Numbered prefixes
Sometimes the text around each line should include a counter: img-1.jpg, img-2.jpg, or Q1:, Q2:. A placeholder that is replaced by the line number covers this without a separate numbering step.
Add a prefix and suffix in your browser
Our Add Prefix & Suffix to Lines tool applies both at once and updates as you type.
- Open Add Prefix & Suffix to Lines and paste your list into Lines of text, one item per line. Sample loads an example.
- Type the text to go before each line in Prefix (added before each line) and the text to go after it in Suffix (added after each line). Either can be empty.
- Or click a preset: Quotes "…",, Bullets •, HTML , Markdown - [ ], SQL ('…'),, Exact match [ ] or Phrase match " ". Presets fill both fields, which you can then adjust.
- To insert the line number, type
{n}anywhere in the prefix or suffix, for example a suffix of-{n}.jpg. - Keep Skip empty lines on so blank lines are left untouched and are not counted by
{n}. - Keep Trim each line first on to remove stray spaces before the prefix and suffix are added, which prevents results like
" red running shoes ". - Copy the output from Lines with prefix and suffix, or click Download.
Finishing touches
The SQL and CSV presets end every line with a comma, including the last one. Most SQL dialects reject a trailing comma, so delete the final one before running the query. If you want everything on a single line instead, pass the result through Comma Separator or Remove Line Breaks.
Other ways to do it
Excel and Google Sheets
Concatenation handles prefixes and suffixes easily:
="https://example.com/p/" & A2 & "?ref=list"
Fill the formula down and copy the results. Spreadsheets are the best option when the prefix depends on another column, such as a category code that varies per row, which a single fixed prefix cannot do.
Code editors
In VS Code, Sublime Text and similar editors, select the lines and add a cursor to each one (in VS Code, Shift+Alt+I adds cursors to the ends of the selected lines on Windows and Linux; check your editor's keyboard shortcuts on macOS). Press Home to jump to the start and type the prefix, then End for the suffix.
Regex find and replace also works in almost every editor:
Find: ^(.+)$
Replace: <li>$1</li>
The $1 refers to the whole line captured by (.+), and requiring at least one character skips blank lines.
Command line
sed is the classic tool:
sed 's/^/https:\/\/example.com\/p\//; s/$/.html/' slugs.txt
Escaping slashes gets awkward with URLs, so many people use a different delimiter, such as sed 's|^|https://example.com/p/|'. For batch jobs across many files, the command line is hard to beat.
Tips and pitfalls
Special characters inside lines
If a line contains the same quote character you are wrapping it in, such as Joe's Cafe inside single quotes, the result breaks SQL and some code. Escape the internal quotes (in SQL, double them: Joe''s Cafe) or use a string-escaping tool such as String Escape for the target language.
Keyword match types
Brackets and quotes are how several ad platforms mark exact and phrase match keywords. Match-type syntax and behaviour are set by each platform and do change over time, so confirm the current rules in the platform's help pages before uploading. To build the keyword list itself, Keyword Combiner creates combinations and our guide to cleaning up a messy keyword list covers tidying it.
Only the numbers
If all you need is a counter at the start of each line, Add Line Numbers offers more numbering control, including start value, step and zero padding.
Windows line endings
Text from Windows files may end lines with \r\n. Our tool splits lines correctly either way. In sed, an invisible \r can end up before your suffix, so convert line endings first if the output looks wrong.
Frequently asked questions
How do I add the same text to the beginning of every line?
Paste the lines, type the text in the Prefix field and copy the result. In a spreadsheet, use ="text" & A2 and fill down.
How do I wrap each line in quotes?
Use the Quotes "…", preset for quoted, comma-ended lines, or Phrase match " " for quotes without commas. Delete the last comma if your format does not allow it.
Can I add a number to each line along with text?
Yes. Type {n} in the prefix or suffix, for example img-{n}.jpg, and it is replaced by the line number, skipping blank lines when that option is on.
How do I turn a list into HTML list items?
Choose the HTML preset, copy the result and place it between <ul> and </ul> tags.
Will blank lines get a prefix too?
Not while Skip empty lines is on. Blank lines stay empty. Switch it off if every line, including blank ones, needs the prefix.