Tools / Add a semicolon to the end of each line
Add a Semicolon to the End of Each Line
Put a semicolon at the end of every line. Useful for CSS declarations, SQL statements and code pasted out of a console.
How it works
Semicolons end a statement in CSS, JavaScript and most SQL dialects, and they separate multiple SQL statements sent in one batch. When you copy a column of declarations or statements out of a spreadsheet, the semicolons are usually missing, and adding them by hand is slow.
This tool appends one semicolon to the end of each line. It does not parse the language, so it will also add a semicolon after a line that is already closed, producing ;;. That is harmless in CSS and JavaScript but can be a syntax error in some SQL clients, so remove duplicates with a find-and-replace on ;; if you see them.
Edge cases
- Lines that already end in a semicolon get a second one. Replace
;;with;afterwards if that matters for your engine. - A semicolon inside a CSS declaration, such as a font stack, is not escaped; only the end of the line is touched.
- SQL statements that end with a block comment will still receive the semicolon after the comment.
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/$/;/' styles.txt
Python
print('\n'.join(l + ';' for l in open('styles.txt').read().splitlines()))
JavaScript
text.split('\n').map(l => l + ';').join('\n');
Excel
=A1&";"
Questions
- Should I add semicolons to JavaScript?
- Automatic semicolon insertion means most JavaScript works without them, but adding them explicitly avoids edge cases where a newline changes meaning, such as a line starting with a bracket. If you are pasting into a console, explicit semicolons make multi-line pastes behave predictably.
- Will this break CSS with a trailing semicolon?
- No. A trailing semicolon before a closing brace is valid CSS, and a doubled semicolon is ignored by browsers. It is safe for stylesheets.
- Does it handle SQL with comments?
- It appends after the whole line, so a statement ending in a comment gets the semicolon after the comment text. Some clients treat that as part of the comment, so put comments above the statement for reliable execution.