Tools / Add text to the end of each line
Add Text to the End of Each Line
Append any text to the end of every line: units, brackets, punctuation, extensions or a repeated tag.
How it works
Appending text per line is the mirror of a prefix and solves a different set of jobs: adding a file extension to a list of names, closing a bracket that was opened on each line, adding a unit to a column of measurements, or tagging each row with the same keyword before import.
If you use the suffix to close something that the line itself opened, such as adding ) to match a ( earlier in the line, the tool cannot check balance for you; it simply appends. For matched pairs it is usually safer to add the opener with the prefix tool and the closer with this one in the same pass, so every line is treated identically.
Edge cases
- The suffix is literal, so include punctuation or spaces you want to keep at the end of the line.
- Blank lines are skipped by default; untick to append to empty lines as well.
- Appending to a line that already ends with the same text duplicates it. There is no de-duplication at the end of a line.
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/$/.jpg/' names.txt
Python
print('\n'.join(l + '.jpg' for l in open('names.txt').read().splitlines()))
JavaScript
text.split('\n').map(l => l + '.jpg').join('\n');
Excel
=A1&".jpg"
Questions
- Can I add a suffix only to some lines?
- Not in one pass. Filter the lines first with the remove empty lines tool or by deleting rows, then apply the suffix to the remainder. Applying a single rule to everything is what makes the operation predictable.
- Does it add a newline at the end?
- The output keeps the line structure of your input. If your input ends without a newline, the output does too, so a file does not gain a phantom final blank line.
- How is this different from the comma tool?
- The comma tool is a shortcut for the single most common suffix. This tool accepts any string, so it covers units, extensions, closing brackets and multi-character text.