TEXT TOOL

Line Counter

Paste text to count total, blank and non-blank lines, unique and duplicate lines and line lengths, then copy it back with line numbers.

0
Total lines
0
Blank lines
0
Non-blank lines
0
Unique lines
0
Duplicate lines
0
Longest line (chars)
0
Shortest line (chars)
0
Average line length
0
wc -l would report

Copy with line numbers


  

About this tool

This line counter counts the lines in any text you paste and splits the total into blank and non-blank lines, which most line counters do not do. It also counts unique and duplicate lines, finds the longest and shortest line, works out the average line length, shows what the wc -l command would report for the same text, and copies the text back with line numbers added. Everything updates as you type and runs in your browser, so nothing you paste is uploaded.

How to use the line counter

  1. Paste your text into the box, or open a text file: a list, a log file, a column copied from a spreadsheet, a block of code or anything else. A short sample list is loaded so you can see the counts.
  2. Read the counts. Total, blank, non-blank, unique and duplicate lines appear in the first row; line lengths and the wc -l figure appear in the second. The status line summarizes the line endings it found.
  3. Set the options if you need them. Turn on Ignore case to treat Apples and apples as the same line, and turn on Count a final line break as an empty last line to match an editor that shows one more line than wc -l.
  4. Copy with line numbers. Pick a separator and a starting number, then copy or download the numbered text.

What counts as a line

A line is the text between two line breaks. The tool recognizes all three common line endings: LF (line feed, used by Linux and macOS), CRLF (carriage return plus line feed, the Windows convention) and a lone CR (used by classic Mac OS). A CRLF pair counts as one line break, not two, so a file saved on Windows gives the same count as the same file saved on Linux.

One detail matters if you care which ending a file uses: browsers may convert line endings to LF when text is put into a text box, so pasted text can report LF breaks even when the source used CRLF. To see the real CRLF, LF and CR counts, use Open a text file. The file is read directly in your browser, the counts use its original line endings, and the status line lists how many of each it found. Editing the text in the box switches back to counting what is in the box.

The definitions behind each number are:

The trailing newline question, and how wc -l counts

Most text files end with a line break after the last line. Should that final break create one more, empty line? This tool says no by default: one\ntwo\n is two lines, the same as one\ntwo. That matches how people read a list. If you need the other convention, turn on Count a final line break as an empty last line and the same text becomes three lines, the third one blank. Many code editors behave this way, showing a numbered empty line after the final line break.

The Unix wc -l command uses a third rule. According to the GNU coreutils manual, -l prints the newline character count, and if a file ends in a non-newline character, its trailing partial line is not counted. So wc -l reports 2 for one\ntwo\n but only 1 for one\ntwo. Because it counts LF characters, a file that uses only CR line endings reports 0. The wc -l would report figure on this page is the number of LF characters in your text, so you can compare it with your terminal. For a file with CRLF or CR-only endings, open the file rather than pasting it, because pasted text may already have been converted to LF.

Worked example

The sample list has nine lines of text and ends with a line break. It contains apples twice, both Bananas and bananas, one empty line and one line holding only two spaces. With the default settings the tool reports:

CountDefaultIgnore case onFinal line break counted
Total lines9910
Blank lines223
Non-blank lines777
Unique lines656
Duplicate lines121

The longest line is line 8, dates and figs from the market, at 30 characters; the shortest is line 9, kiwi, at 4. The seven non-blank lines hold 68 characters in total, so the average is 9.7. The text contains 9 LF characters, so wc -l would also report 9. The first lines of the numbered output, with the default period separator, are:

1. apples
2. Bananas
3. cherries
4. 

Common mistakes

Use cases

To sort the lines, use the Text Sorter; to remove repeated lines, use the Duplicate Remover; and to count words, characters and sentences rather than lines, use the Word Counter.

Frequently asked questions

How do I count the number of lines in a text?

Paste the text into the box on this page and read the Total lines figure. It updates as you type. The count splits on every line break, whether the text came from Windows, Mac or Linux, and it also shows blank, non-blank, unique and duplicate lines so you can see what the total is made of.

Why does wc -l give a different number than my editor?

wc -l counts newline characters, not lines. If the last line has no line break after it, wc -l does not count that line, while an editor still shows it. If the file does end with a line break, many editors show one extra empty line. Use the trailing line break option here to match either convention.

Does a line with only spaces count as blank?

Yes. A line that contains nothing but spaces, tabs or other whitespace is counted as blank, because it looks empty on screen. It is still included in the total. If you need to know where those lines are, the numbered output shows every line, including whitespace-only ones, with its line number.

How can I count lines in a Word document or PDF?

Copy the text from the document and paste it here. Word and PDF readers wrap long sentences to fit the page, but copying usually keeps only real paragraph breaks, so the count here is the number of paragraphs or hard line breaks rather than the wrapped lines you see on the printed page.

Is there a limit to how much text I can paste?

There is no fixed limit set by the tool. Everything runs in your browser, so the practical limit is your device memory. Lists with tens of thousands of lines count almost instantly on a typical computer. Very large files may make the page slow while typing, so paste once and then read the results.

How do I add line numbers to text?

Paste the text, then use the Copy with line numbers section. Choose a separator such as a period, colon, tab or pipe, set the starting number, and decide whether blank lines get a number. Click Copy numbered lines, or download the result as a plain text file.