📄

Line Counter

A line counter splits text at every line break and reports how many lines it holds. Paste four log rows with one blank line between them and a final line break and this page shows Total lines 6, Non-empty lines 4 and Empty lines 2, because that last break opens a sixth, empty line. Lines that contain only spaces or tabs count as empty, and Remove Empty Lines deletes them from the box in one click.

Total lines
Non-empty lines
Empty lines

Embed this tool on your website

× px

                        

💡 Integration Tip

Copy the embed code and paste it into your website HTML. The responsive version adapts to all screen sizes automatically.

4.5
20 ratings

Popular Tools

No more tools to show
Explore All Tools

About Line Counter

Line Counter reads whatever sits in the numbered box and splits it at every line break, the character the Enter key inserts. Total lines is the number of segments that split produces, Non-empty lines counts the segments that still hold something once spaces and tabs are stripped, and Empty lines is the difference. The three figures update on every keystroke.

Because the count is of segments and not of break characters, Total lines is always exactly one more than wc -l reports for the same text: wc -l counts line feeds, and text ending with one has an empty segment after it. Windows CRLF, Unix LF and classic Mac CR endings all give the same answer, because the box normalises them to a single line feed before counting. A line of spaces, tabs or non-breaking spaces is scored as empty; a line holding a zero-width space is content, because that character is not whitespace.

Remove Empty Lines rewrites the box with the blank and whitespace-only lines dropped and the rest rejoined by single breaks, so the four-row log sample comes back as 4, 4 and 0. Clear empties the box, and an empty text is still one empty line by the rule above, so the counters read 1 and 1 afterwards while a freshly loaded page reads 0. Neither button can be undone with Ctrl+Z.

The page counts lines and nothing else: there is no upload button, no word or character count, no sorting or duplicate removal, and no knowledge of the language your code is written in, so comment lines count as content. The number column draws one row per line, which makes very large pastes slow: in our tests 1,000 lines counted in well under a second, 10,000 lines took a few seconds and 50,000 lines took over a minute. Everything runs in your browser and the text is never uploaded.

Use Cases

A developer sizing a refactor pastes a source file and reads Non-empty lines, so the blank separator lines between functions are left out and the figure reflects the code that actually has to be reviewed.
A support engineer pastes a slice of an error log to see how many entries it holds before opening a ticket, and Empty lines exposes the double spacing some log shippers insert between records.
A data analyst pastes a CSV export and compares Total lines with the row count the database reported; a difference of exactly one usually means the file ends with a trailing line break, not that a row went missing.
A poet entering a competition capped at 40 lines pastes the poem and reads Non-empty lines for the verse count, while Total lines shows the figure that includes the stanza breaks.
A teacher building a vocabulary list pastes it, clicks Remove Empty Lines to strip the gaps left by copying out of a PDF, and checks that the counter now matches the 50 entries the exercise is supposed to have.

How to use

1

Paste or type your text into the box with the line numbers down its left edge

2

Read Total lines for every line break in the text, including the empty line a trailing break opens

3

Read Non-empty lines for the rows that carry content and Empty lines for the blank ones

4

Click Remove Empty Lines to drop the blank rows from the box and watch the counters update

5

Click Clear to empty the box before you paste the next block of text

Pro Tips

  • Total lines counts one more than the rows you can see whenever the text ends with a line break, because that break opens an empty last line. Press Backspace once at the very end of the box and the figure drops by one.
  • A line of spaces or tabs is scored as empty, so when Non-empty lines is lower than you expected, look for indentation left behind on otherwise blank lines rather than for missing text.
  • Remove Empty Lines edits the text itself, not just the counters, and Ctrl+Z will not bring the blank lines back. Copy the cleaned text out of the box before you press Clear.
  • Text copied from a Windows file, a Unix file or an old Mac file gives the same three numbers: the box turns CRLF and lone CR endings into single line feeds before counting, so you never have to convert the file first.
  • Paste in slices once a file runs to tens of thousands of lines. The number column on the left draws one row per line, and that is what makes a very large paste crawl.

Troubleshooting

Problem:

After clicking Clear the counters read 1 total line and 1 empty line, even though the box is empty.

Solution:

That is the counting rule applied to an empty text: with no line break to split on there is exactly one segment, and it is empty. The 0, 0 and 0 you see when the page first opens is the untouched state, before anything has been counted. Reload the page if you want those zeros back.

Problem:

The page freezes for several seconds when I paste a very long file.

Solution:

The number column on the left draws one row per line, so its cost grows with the file. In our tests 1,000 lines counted in well under a second, 10,000 lines took a few seconds and 50,000 lines took over a minute. Paste long logs in slices, or run wc -l on the file and add one to its answer.

Problem:

A line that looks blank is being counted under Non-empty lines.

Solution:

Something invisible is sitting on it. Spaces, tabs, carriage returns and non-breaking spaces are all ignored, so those still count as empty, but a zero-width space (U+200B) or a stray full stop is content. Delete the line and retype the break, or click Remove Empty Lines and check whether the row survives.

Frequently Asked Questions

A line counter is a tool that splits a block of text at every line break and reports how many lines it contains. This one shows three figures at once, Total lines, Non-empty lines and Empty lines, so you can see both the raw size of a file and how much of it carries content. Four log rows separated by one blank line and ending with a break give 6, 4 and 2.

Open the file in any editor, select everything with Ctrl+A (Cmd+A on a Mac), copy it, and paste it into the numbered box on this page; the counters update as the text lands. There is no upload button, so the file itself never leaves your computer. On Linux or macOS the shell equivalent is wc -l file.txt, which returns one less than Total lines because it counts break characters.

Yes. Total lines includes them and Empty lines counts them separately, so you can subtract one from the other. A line is scored as empty when nothing is left after spaces, tabs, carriage returns and non-breaking spaces are stripped, which means a line holding two spaces counts as empty rather than as content. Click Remove Empty Lines to delete those lines from the box.

Yes. The counter works on the segments between breaks, so "alpha" and "beta" with nothing after "beta" is 2 lines. Add a break after "beta" and Total lines becomes 3, because the break opens a new, empty line. Non-empty lines stays at 2 in both cases, which is why it is the more stable figure when you are comparing two files.

Windows Notepad has no line-count command. It can show the caret position in the status bar, which you switch on from the View menu, so the usual trick is to press Ctrl+End and read the Ln number on the last line. That gives one number and nothing else; pasting the text here is faster and also separates the blank lines from the lines that carry content.

Word reports lines in its Word Count dialog, on the Review tab, where Lines sits below Paragraphs. That figure counts the lines as laid out on the page, so it changes when you alter the margins, the font or the line spacing. If you want the number of paragraphs, one per press of Enter, paste the text into this page instead: Total lines counts line breaks, not wrapped rows.

Excel counts rows rather than lines: =COUNTA(A:A) returns the number of filled cells in column A. Line breaks inside a single cell, the ones Alt+Enter inserts, are a different thing and are counted with =LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1, since CHAR(10) is the line feed. Copying a column out of Excel and pasting it here gives the same row count with the blank rows listed separately.

Paste the file and read Non-empty lines: that is the usual source-lines-of-code figure, because blank separator lines are excluded from it. Comment lines are still counted, since nothing on this page parses a programming language, so subtract them yourself when you need a strict count. To size a change, paste the old file and the new one in turn and compare the two figures.

Paste the text into the box on this page and read the three counters. The counting is done by a small script inside your browser, so nothing is uploaded, no account is needed and the numbers appear as you type. Closing the tab discards the text: it is not saved on the page or anywhere else, which is what makes this safe for log extracts and unpublished writing.

wc -l counts line-break characters, while this page counts the segments between them, so Total lines is always exactly one more than wc -l for the same text. A four-row log with one blank line and a trailing break gives wc -l 5 and Total lines 6. If you want the wc -l figure, read Total lines and subtract one; if you want the rows that carry content, read Non-empty lines.

FreeWebTools AI
Powered by free AI models · Full chat →