Append Prefix and Suffix to Text Lines
Add custom prefix and suffix to each line of text instantly. Supports trimming, empty line skipping, line numbering, and bulk text processing.
About
Manually prepending or appending strings to hundreds of text lines introduces transcription errors and consumes hours of labor. A misplaced delimiter in a CSV column or a missing SQL quote wrapper can cascade into data corruption across entire pipelines. This tool processes each line of input text by attaching a user-defined prefix before and a suffix after every line, with options to trim whitespace, skip empty lines, and inject sequential line numbers. It operates entirely in-browser with zero data transmission.
Common applications include wrapping database values in SQL quote syntax, adding HTML tags to plain text lists, prepending log-level identifiers to raw log entries, and constructing bulk CLI commands from hostname lists. The tool assumes UTF-8 input and treats newline characters (LF or CRLF) as line delimiters. Note: lines containing only whitespace are treated as empty when the skip-empty option is active, after trimming is applied.
Formulas
The transformation applied to each line Li in the input text is a simple concatenation operation:
Where P = the user-defined prefix string, S = the user-defined suffix string, Li = the content of line i (optionally trimmed), and Ni = the optional line number component (empty string when numbering is disabled).
When line numbering is enabled, Ni is computed as:
Where w = digit width calculated as floor(log10(totalLines)) + 1, and D = the numbering delimiter (default: ". "). Lines are processed sequentially. When skip-empty is active, empty lines are excluded from the output array entirely, and the numbering counter i only increments for non-empty lines.
Reference Data
| Use Case | Prefix | Suffix | Example Input Line | Example Output Line |
|---|---|---|---|---|
| SQL Value Wrapping | " | ", | John Doe | "John Doe", |
| HTML List Items | <li> | </li> | Apples | <li>Apples</li> |
| CSV Quoting | " | ", | raw value | "raw value", |
| Markdown Checkboxes | - [ ] | Buy groceries | - [ ] Buy groceries | |
| Log Level Prefix | [INFO] | Server started | [INFO] Server started | |
| Bash Echo Commands | echo " | "; | Hello World | echo "Hello World"; |
| XML Tags | <item> | </item> | Widget | <item>Widget</item> |
| URL Path Building | https://api.example.com/ | /details | user/42 | https://api.example.com/user/42/details |
| Python List Strings | " | ", | alpha | "alpha", |
| Numbered Prefix | Step (+ numbering) | . | Mix ingredients | Step 1. Mix ingredients. |
| CSS Class Prefix | . | {} | header | .header {} |
| Regex Alternation | ( | )| | pattern | (pattern)| |
| Email Domain Append | @company.com | jdoe | [email protected] | |
| Comment Lines | // | deprecated function | // deprecated function | |
| Pipe Delimiter | | | | | Cell Data | | Cell Data | |