Line counting, split on the standard newline
A line is one element of the array produced by splitting the input on \r?\n. An empty input gives Lines: 0. A single line with no terminating newline gives Lines: 1. Three lines separated by two newlines gives Lines: 3. The split treats CRLF (Windows) and LF (Unix/macOS) the same way, so a Windows-pasted file with \r\n endings reports the same count as the Unix equivalent.
The Mode select narrows the count. All Lines is the total. Non-Empty drops lines that are empty after the optional trim. Empty Only reports just the empty-line count, useful when you are trying to figure out how many blank rows are in a CSV or how many paragraph breaks exist in a draft.
Trim changes what counts as empty. Off, only zero-length strings count as empty: " " (three spaces) is non-empty. On, each line is trimmed first, so any line that is whitespace-only is treated as empty. The total All Lines count is unaffected by Trim.
How to use count lines in text
- 1Paste or type your text into the input panel on the left.
- 2The line count appears in the output panel as you type.
- 3Switch Mode to
Non-EmptyorEmpty Onlyto filter the count. - 4Turn on Trim if whitespace-only lines should count as empty.
- 5Click Copy in the output header to copy the count.
Keyboard shortcuts
Drive TextResult without touching the mouse.
| Shortcut | Action |
|---|---|
| Ctrl F | Open the find & replace panel inside the input Plus |
| Ctrl Z | Undo the last input change |
| Ctrl Shift Z | Redo |
| Ctrl Shift Enter | Toggle fullscreen focus on the editor Plus |
| Esc | Close find & replace, or exit fullscreen |
| Ctrl K | Open the command palette to jump to any tool Plus |
| Ctrl S | Save current workflow draft Plus |
| Ctrl P | Run a saved workflow Plus |
What this tool actually does
Splits on \r?\n: LF and CRLF both work
The split regex matches a single LF or a CRLF pair, so a file pasted from Windows or Unix produces the same count. The status bar at the bottom of the input panel shows which line ending was detected.
Final line counts even without a trailing newline
Splitting on \r?\n in JavaScript produces an array whose last element is the text after the final newline. "a\nb" splits to ["a","b"], count 2. "a\nb\n" splits to ["a","b",""], count 3 (the trailing empty becomes the third line).
Mode: All, Non-Empty, or Empty Only
Default All Lines returns the total. Non-Empty filters out empty lines (subject to the trim toggle) and reports the remainder as Non-empty lines: N. Empty Only reports the empty-line count as Empty lines: N.
Trim changes the empty test
Off (default), a line is empty only when its length is zero. On, each line is trimmed first via String.trim, so " ", "\t", and "" are all empty. Trim does not change the All Lines total; it only affects which lines are counted as empty.
Empty input gives Lines: 0
A zero-length input is the one case where split would return [""] (count 1) but the tool special-cases it to 0, so an empty paste reads as zero rather than one phantom line.
Worked example
Five entries after splitting on \n. Switch Mode to Non-Empty with Trim off and the count is 4 (the empty fourth line is dropped, the spaces-only line still counts). Turn Trim on and it drops to 3.
first line second line fifth line
Lines: 5
Settings reference
| Option | Effect on output |
|---|---|
| Mode = All Lines (default) | Reports the split-array length as Lines: N. |
| Mode = Non-Empty | Reports the count of lines that are not empty (per the trim setting) as Non-empty lines: N. |
| Mode = Empty Only | Reports only the empty-line count as Empty lines: N. |
| Trim (default off) | Off: only zero-length lines are empty. On: whitespace-only lines are also empty. |
| Empty input | Output is Lines: 0. |
| Line endings | LF (\n) and CRLF (\r\n) both split the same way. |
FAQ
Does the count include the last line if it has no trailing newline?
"a\nb" reports 2. "a\nb\n" reports 3 (the trailing empty after the final newline is the third line).How are blank lines counted?
All Lines. They are excluded from Non-Empty and counted in Empty Only. Whether a whitespace-only line is empty depends on the Trim toggle.Does it handle Windows line endings?
\r?\n, which matches both LF (Unix/macOS) and CRLF (Windows) without producing phantom empty lines.How do I count only blank lines?
Empty Only. Turn on Trim if whitespace-only lines should also count as blank.