Tools / Add a prefix to each line
Add a Prefix to the Start of Each Line
Put any text at the beginning of every line: bullets, comment markers, log tags or a repeated keyword.
How it works
A prefix is whatever you want in front of the line: a dash for a bullet list, # for a comment block, // for JavaScript, ERROR for a log excerpt, or a repeated column name when you are building SQL. The same string is added to every line, exactly as typed, including spaces.
Because the prefix is literal, trailing spaces matter. Typing - with a space produces a valid Markdown bullet; typing - without one produces -item. That is why the box is a plain text field with no auto-formatting: what you type is what you get, which is the only predictable behaviour when the prefix might be a regex character, an emoji or a tab.
Edge cases
- Spaces are preserved exactly, so type the trailing space yourself if you want
- itemrather than-item. - Blank lines are skipped by default to avoid a line containing only your prefix.
- Special characters are not escaped; a prefix like
$is inserted as plain text.
Do it in code instead
The same result with a shell one-liner or a few lines of Python, if you would rather automate it:
Bash (sed)
sed 's/^/- /' list.txt
Bash (awk)
awk '{ print "- " $0 }' list.txt
Python
print('\n'.join('- ' + l for l in open('list.txt').read().splitlines()))
Excel
="- "&A1
Questions
- How do I add a different prefix to different lines?
- This tool applies one prefix to all lines. If you need alternating prefixes, split the file into two blocks, apply a prefix to each, then join them. For line numbers use the number lines tool, which adds a counter instead of fixed text.
- Can I add a tab?
- Yes. Paste a tab character into the prefix box. It is inserted literally, so it survives copying into most editors, though some web forms collapse tabs on paste.
- What about a prefix containing a backslash?
- It is inserted as typed, without escape processing, so a Windows path prefix stays readable. That is the opposite of the quotes tool, which deliberately escapes quotes to keep output valid.