Add Prefix to Text Lines
Add a custom prefix to every line of text instantly. Supports numbering, separators, empty line skipping, and bulk text processing.
About
Prepending a consistent prefix to each line of a text block is a routine operation in data preparation, log formatting, and code commenting. Manual editing across hundreds of lines introduces typos, inconsistent spacing, and wasted time. This tool processes n lines in O(n) time, applying a user-defined prefix string P with a configurable separator S to produce output lines of the form P + S + Li. It handles edge cases: empty lines, trailing whitespace, and optional zero-padded line numbering. The tool assumes UTF-8 input and preserves original line breaks.
Formulas
Each input line Li is transformed by concatenating the prefix P, an optional separator S, and the original line content:
When line numbering is enabled with zero-padding width w, the prefix becomes a composite:
Where P is the user-defined prefix string. S is the separator character (space, tab, colon, or none). Li is the i-th line of input text. w is computed as floor(log10(n)) + 1, where n is the total line count. When the skip-empty-lines option is active, lines where trim(Li).length = 0 are passed through unmodified.
Reference Data
| Prefix Use Case | Typical Prefix | Separator | Context |
|---|---|---|---|
| SQL Comments | -- | Space | Disabling SQL statements in bulk |
| Python Comments | # | Space | Commenting out code blocks |
| C/Java Comments | // | Space | Single-line comment blocks |
| Markdown Lists | - | Space | Converting plain lines to bullet lists |
| Ordered Lists | 1. | Space | Creating numbered Markdown lists |
| Email Quoting | > | Space | Quoting replied text in email or Markdown |
| Log Tagging | [INFO] | Space | Categorizing log entries by severity |
| Error Tagging | [ERROR] | Space | Marking error-level log lines |
| CSV Field Add | value, | None | Prepending a column to CSV rows |
| Indentation | (4 spaces) | None | Adding indent level to code blocks |
| Tab Indentation | \t | None | Adding tab-based indentation |
| HTML List Items | <li> | None | Wrapping lines in list item tags |
| Bash Echo | echo | Space | Converting text lines to shell echo commands |
| Git Commit Prefix | fix: | Space | Conventional commit message formatting |
| Timestamp | 2024-01-15 | Space | Date-stamping log or journal entries |
| Namespace | app. | None | Adding namespace prefix to config keys |
| TODO Marker | TODO: | Space | Marking lines as action items |
| Checkbox (MD) | - [ ] | Space | Creating Markdown task lists |
| Arrow Indicator | → | Space | Visual indicators in documentation |
| Custom Label | [REVIEW] | Space | Flagging lines for peer review |