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
- 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.
- Read the counts. Total, blank, non-blank, unique and duplicate lines appear in the first row; line lengths and the
wc -lfigure appear in the second. The status line summarizes the line endings it found. - Set the options if you need them. Turn on Ignore case to treat
Applesandapplesas 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 thanwc -l. - 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:
- Total lines: every line, blank or not. Empty input has 0 lines; text with no line break at all has 1.
- Blank lines: lines that are empty or contain only whitespace such as spaces or tabs. A line holding two spaces looks empty and is counted as blank.
- Non-blank lines: total minus blank, that is, lines with at least one visible character.
- Unique lines: the number of different non-blank lines, using an exact match.
applesandapples(with a trailing space) are different lines. With Ignore case on, letters are compared in lowercase. - Duplicate lines: extra copies, that is, non-blank lines minus unique lines. Three copies of one line count as two duplicates. This is how many lines an exact-match pass of the Duplicate Remover (with whitespace trimming off) would delete.
- Longest, shortest and average length: measured in characters over non-blank lines, with the line number shown in the status line. Line break characters are not counted, but spaces are. Characters are Unicode code points, so an accented letter counts as one; an emoji built from several code points counts as more than one.
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:
| Count | Default | Ignore case on | Final line break counted |
|---|---|---|---|
| Total lines | 9 | 9 | 10 |
| Blank lines | 2 | 2 | 3 |
| Non-blank lines | 7 | 7 | 7 |
| Unique lines | 6 | 5 | 6 |
| Duplicate lines | 1 | 2 | 1 |
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
- Off-by-one totals. If your count is one higher or lower than another program, check the trailing line break option first; it is the usual cause.
- Invisible spaces. Lines that look identical but count as unique often differ by a trailing space or tab. Run the text through the Text Cleaner to trim spaces, then count again.
- Wrapped lines. A long line that wraps on screen is still one line. Only an actual line break starts a new one.
- Case differences.
Bananasandbananasare two unique lines unless Ignore case is on.
Use cases
- Lists and spreadsheets. Copy a column from Excel or Google Sheets and paste it here: each row becomes one line, so the non-blank count tells you how many filled cells you copied, and the duplicate count shows repeated entries. To count the lines inside a single Excel cell instead, Exceljet documents the formula
=LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1, which counts line breaks and adds one. - Code. Count the lines in a function or file, see how much of it is blank, and copy a snippet with line numbers for a code review, a bug report or documentation.
- Logs and data files. Check how many records a CSV or log excerpt holds, and compare with
wc -loutput from a server. - Writing. Count lines of poetry or song lyrics, or check a list of names or keywords against a limit.
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
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.
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.
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.
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.
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.
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.