Line Counter_

Paste anything with line breaks and get more than a total: how many lines actually have content, how many are blank, how many repeat, which line is longest, and which lines run past a length you set. Every line is numbered the way an editor numbers it, so "which ones" is answerable and not just "how many".

The counting rules are published rather than assumed. Most tools quietly pick a convention for the trailing newline, for what counts as blank, and for how length is measured, and none of them tell you which — that ambiguity is usually why you are here checking a number against a second opinion. This page states each rule, and shows the trailing-newline decision live for the text you pasted. Nothing is uploaded.

toolkit.codes/line-counter
0
Total lines
0
Non-blank
0
Blank
0
Unique
0
Duplicates

Paste text to count its lines

Longest line
—
Shortest non-blank
—
Average length
—
Line endings
—
No lines over 80 characters.
Numbered_Lines
UTF-8
Ready
100% LOCAL
Input
Anything with newlines in it — a CSV export, a log excerpt, a pasted column from a spreadsheet, a list somebody sent twice. CRLF, LF and a bare carriage return are all read as breaks.
Output
The total, then the numbers that explain it: how many were blank, how many repeat, which is longest and shortest, and how many exceed a length you choose.
Processing
Counted in this tab, and the counting rules are published on the page rather than left implicit, so a number you disagree with can be checked instead of argued about.
Limits
Longest and shortest are measured over non-blank lines only, and length is counted in code points. An emoji or a flag is therefore one unit here and may be several in a database column that measures bytes.
Mixed endings are the silent one
A file that uses CRLF in some places and LF in others still opens fine and still looks right, then breaks an import that trusted one or the other. The endings are counted separately, the dominant one is named, and a file carrying more than one kind is flagged rather than quietly normalised away.

Counting lines is less obvious than it looks

Where the off-by-one comes from

Almost every text file ends with a line break, and that break creates the disagreement. Is a⏎ one line or two? Both answers are defensible. Treat the break as a terminator closing the line it follows and the answer is one — what editors show, and what this page does. Treat it as a separator between lines and you get an empty second line, which is how a naive split behaves. Both readings are internally consistent, which is exactly why tools differ. The rule here is fixed, published in the table below, and reported live for whatever you paste.

Three ways to end a line

The break itself is not one character everywhere. Teletypes needed two motions — a carriage return to bring the head back, a line feed to advance the paper — and that pair survived into DOS and Windows as CRLF. Unix kept only the line feed, and modern macOS follows Unix. Classic Mac OS used the carriage return alone. All three are recognised here, in any mix — which matters because a tool that only knows line feeds reads a carriage-return-only file as one enormous line.

What the other numbers are for

A bare total rarely settles anything alone. Blank versus non-blank tells you whether an export has the rows you expected or is padded with empties. Unique versus duplicate flags a list concatenated twice, before you deduplicate for real. Longest and shortest, with their line numbers, find the row that will break a fixed-width import or the column limit a linter is complaining about — and the limit box turns that into a list of which lines to fix. These are diagnoses, not repairs.

Why two tools give two answers

The classic case is wc -l, which does not count lines at all — it counts newline characters. On a file whose last line has no break, that line is invisible to it, so it reports one fewer than your editor's final line number. Not a bug: POSIX defines a line as ending in a newline. Add whitespace-only rows that some tools score as content and others as blank, and two honest tools can disagree twice over on one input. The fix is not a better tool but a stated rule, which is what the second table below is.

How to use

  1. 01Paste text into the box, or use Upload to read a file from your device — it is read in the browser and never sent anywhere. Every count updates as you type.
  2. 02Read the tiles for the totals, then the detail row for the longest and shortest lines, the average length, and which line endings were found. The line under the tiles states how the final line break was handled for your specific input.
  3. 03Set a length limit to flag long lines. The count and the line numbers appear next to it, and Copy_Line_Numbers puts just those numbers on your clipboard for pasting into an issue or a script.
  4. 04Use the numbered preview to find a flagged line quickly — the numbers match what your editor shows. Copy_Report copies every metric as plain text.

Four arguments a line count ends

Did the export drop rows?

A CSV should hold 5,000 records. Total says 5,001, non-blank says 5,000 — the header plus a trailing blank.

Input
a pasted CSV export
Output
5,001 total · 5,000 non-blank · 1 blank

Which rows will break the import?

A field accepts 60 characters. Set the limit and get the number of every row that overruns, ready to paste into a ticket.

Limit
60
Output
3 lines over 60 — lines 14, 208, 3,991

Was this list pasted twice?

Total and unique differing by exactly half is the signature of a doubled paste.

Input
a list of email addresses
Output
840 total · 420 unique · 420 duplicates

Is this log excerpt complete?

Mixed line endings in an uploaded excerpt show it was assembled from two sources, not copied from one.

Input
a pasted log excerpt
Output
Mixed — 412 LF, 30 CRLF

How lines end, by platform

ConventionCharactersBytesWhere it comes fromEffect on a count
LF\n (0x0A)1Unix, Linux, modern macOS, and most things on the webThe baseline every tool handles
CRLF\r\n (0x0D 0x0A)2DOS and Windows, inherited from teletype mechanicsCounted once here, not twice. Tools that split on \r and \n separately double the count
CR\r (0x0D)1Classic Mac OS, before OS XA tool that only knows \n sees the whole file as one line

All three are recognised and can be mixed within one input. A mixture nobody intended usually means the file was edited on two platforms, or assembled by pasting.

The rules this page applies

QuestionRule hereExample
Does a trailing newline start a new line?No — a single final break ends the last linea⏎ is 1 line, a⏎⏎ is 2
What is empty input?Zero lines, not one"" is 0 lines
What counts as blank?Nothing visible — empty or whitespace onlyA line of three spaces is blank
Are whitespace-only lines separated out?Yes, apart from truly empty onesBoth appear in the copied report
What does Unique count?Distinct line values, blank lines includeda⏎b⏎a → 2 unique
What does Duplicates count?Lines repeating an earlier line, not distinct repeated valuesa⏎b⏎a⏎a → 2 duplicates
How is length measured?Code points, so an emoji is one character👋👋 has length 2
Which lines can be longest or shortest?Non-blank ones onlyOtherwise a blank line makes shortest 0
What is the average over?Non-blank lines, to one decimalConsistent with shortest
When is a line over the limit?Strictly longer — equal is not overAt limit 10, a 10-character line passes

Published because no competitor publishes theirs. If a number here disagrees with another tool, the cause is one of these ten rows — compare them rather than assuming either tool is broken.

Habits that keep two counts agreeing

  • Compare total against non-blank first. A gap means blank rows — usually a paste artefact, not real data.
  • Total minus unique is your duplicate count in one subtraction — a fast check before running any deduplication.
  • When a number disagrees with another tool, check the trailing newline first. It is the most common single-line discrepancy.
  • Set the limit to your real constraint — a column width, a linter rule, a terminal width — and let the line numbers say where to look.
  • Upload a file rather than pasting it when the line endings matter — a text box rewrites them all to LF first.

Why your editor and this page differ by one

The trailing newline is an off-by-one waiting to happen

A file ending in a line break can honestly be called N lines or N+1, depending on whether that break terminates the last line or separates two. This page treats it as a terminator, so a⏎ is one line, and says so under the tiles. Any tool disagreeing by exactly one is almost certainly making the other choice, not miscounting.

Mixed endings from two platforms

A file edited on Windows and then on Linux ends up with CRLF on some lines and LF on others. Counts here stay correct because all three conventions are recognised, but downstream the mixture does real damage: a diff can show every line as modified when nothing meaningful changed, turning a two-line pull request into a thousand-line one.

Pasting into any web box destroys the line endings

A browser text box normalises CRLF and CR to plain LF the instant text lands in it, so by the time a web tool sees your paste the original endings are gone. Nothing reading a textarea can tell you what a file really held — this page included, which is why pasted text is labelled browser-normalised. Upload the file and the real endings survive. Counts are unaffected: normalising swaps one break for another.

Your editor and your terminal answer different questions

An editor numbers the lines it displays and will happily show a final line with no terminator. Command-line tools follow the POSIX definition instead. Neither is wrong — the gap appears on exactly the files whose last line is unterminated.

wc -l counts newline characters, not lines

The mechanism behind the previous point. Run it on a file whose last line has no break and that line simply is not counted — a one-line file with no terminator reports 0. It does what it says: counts 0x0A bytes. For lines regardless of termination, grep -c "" is the usual substitute.

A line of spaces is not empty

Whitespace left by a careless paste produces lines that look blank and are not, and tools split on whether to score them as content. Here they are blank, but also counted separately as whitespace-only — so if another tool reports more non-blank lines, that gap is where to look.

Splitting rules, endings, and what counts as blank

File handling
Uploads are read inside the page with the browser File API and are never transmitted; Download writes out what is already in the tab.
Splitting
CRLF, LF and bare CR all split a line, mixed freely in one input; a CRLF pair is one break, never two
Endings detection
Accurate for uploaded files; pasted text is normalised to LF by the browser before any script can read it, so that case is labelled rather than asserted
Trailing newline
A terminator, not a separator — one final break creates no empty last line, and the decision is displayed for the current input
Length unit
Code points, so an emoji or an accented character counts as one; UTF-16 units would over-count both
Longest / shortest / average
Computed over non-blank lines only, with 1-based line numbers matching an editor
Length limit
Configurable, strictly-greater, blank lines never flagged; values below 1 clamp to 1
Not included
No lines-of-code mode — separating code from comments needs the language
Large inputs
Every metric covers the whole input; the numbered preview caps at 5,000 lines with a notice so the tab stays responsive
Network
None from tool code. A test sweep calls every function this page uses with fetch and XMLHttpRequest replaced by stubs that throw, so a stray request fails the build instead of shipping. Disconnect from the network and the page still works.

Questions about counting lines and line endings

Does a file ending in a newline have one line or two?

One, by the rule this page uses and the one editors use: the final break ends the last line rather than starting an empty one. The opposite reading is also self-consistent, which is why tools disagree — so the rule is stated and shown live for whatever you paste.

Why does wc -l give a different number?

Because it counts newline characters rather than lines. If your last line has no trailing break it is not counted, so wc -l reports one fewer — the POSIX definition. Use grep -c "" to count every line regardless.

Do blank lines count?

They count towards the total and are reported separately as blank, so you can read either number. Lines of only spaces or tabs are blank here too, and counted apart from truly empty ones — some tools call those non-blank, which is a common source of a small discrepancy.

How do I count only lines with content?

Read the Non-blank tile. It excludes empty and whitespace-only lines, which is usually the number you want when checking whether an export contains the rows you expected.

Does this handle Windows and old Mac line endings?

Yes — CRLF, LF and bare CR all split lines, mixed freely. Upload the file to see which it really uses: pasting into any web text box rewrites them all to LF before a script can look, so pasted text is labelled browser-normalised rather than reported as fact.

Can it count lines of code, excluding comments?

No, deliberately. Doing it properly means knowing the language, and comment syntax varies enough — plus markers appear inside strings — that a guess would miscount often enough to be worse than no answer.