Free text tool

Line Counter

Count lines in any text or list as you paste it, see how many are blank or repeated, and tidy the list with one click: drop empty lines, remove duplicates, sort or number it.

0Total lines
0Non-empty lines
0Blank lines
0Unique lines
0Duplicate lines
0Longest line (chars)
0Words
0Characters

Count lines in seconds, then tidy the list

A form only accepts 500 keywords. A class register has to match the attendance sheet. You want to know how many guests replied before you book the tables. Scrolling and counting by eye goes wrong somewhere around line 40, and a spreadsheet is a lot of effort for a quick answer.

Paste the text into the box above and the counter does the work while you type. You get the total number of lines, plus a breakdown of how many are empty, how many are repeats and how long the longest one is. If the numbers show a problem, such as gaps or the same name entered twice, the buttons under the box fix it in one click. That's why people use it as a list counter as much as a line counter.

Using the line counter, step by step

  1. Paste or type your text. Put one item on each line. Text copied from Excel, Google Sheets, Notepad, Word, email or a terminal window all works.
  2. Read the eight numbers under the box. They refresh on every keystroke, so you can watch the count change as you edit.
  3. Set how lines are compared. These two options only affect the unique and duplicate figures and the Remove duplicates button:
    • Ignore case makes "Mumbai" and "mumbai" count as the same entry.
    • Ignore spaces at line ends (on by default) stops an invisible trailing space from making two identical lines look different.
  4. Clean up, if you need to. Remove blank lines, remove duplicates, sort A–Z or Z–A, add numbers or trim spaces.
  5. Copy the result back into your document. If a button did something you didn't want, Undo restores the text from before that one change.

The eight numbers, explained

StatisticWhat it tells you
Total linesThe full line count, gaps included.
Non-empty linesLines with at least one visible character. This is usually the number of real entries in a list.
Blank linesLines that are empty or hold nothing but spaces or tabs.
Unique linesHow many different entries there are, counting each value once.
Duplicate linesExtra copies of an entry that already appeared higher up. Remove duplicates deletes exactly this many.
Longest line (chars)The length of the longest single line, which is handy when a field has a character limit.
WordsGroups of characters separated by spaces, tabs or line breaks.
CharactersEverything, including spaces, with each line break counted as one character.

Two checks always hold: total lines equals non-empty plus blank, and non-empty equals unique plus duplicate. If a list "should" have 120 names and the non-empty figure says 124, the duplicate count tells you straight away whether repeats explain the difference.

A worked example: tidying a keyword list

Here is a short list of the kind you might export from a keyword tool or collect from a team. It has a mixed-case repeat, an empty line, and a repeat with two invisible spaces at the end of line 6:

red running shoes
Red Running Shoes
blue trail shoes

running shoes for women
blue trail shoes  
kids running shoes

Pasted into the counter with the default settings, it shows 7 total lines, 6 non-empty, 1 blank, 5 unique and 1 duplicate. The longest line is 23 characters ("running shoes for women"), and there are 19 words. The duplicate is the second "blue trail shoes": its trailing spaces are ignored, so it matches the first.

Tick Ignore case and the figures change to 4 unique and 2 duplicates, because "Red Running Shoes" now matches "red running shoes". Then click Remove blank lines, Remove duplicates and Sort A–Z. You are left with four clean lines:

blue trail shoes
kids running shoes
red running shoes
running shoes for women

If you wanted "Red Running Shoes" kept instead, move it above the lowercase version before removing duplicates.

Why other programs give a different line count

If you check the same text somewhere else, you may get a number that is one higher or one lower. That is not a mistake by either program. It comes down to one question: does a line break at the very end of the text start a new line?

This counter says no. A final line break simply finishes the last line, so "a, b, c" typed on three lines is 3 lines, with or without a line break after "c". Here is how some common tools handle the same two pieces of text:

Tool or methoda⏎b⏎c (no break at end)a⏎b⏎c⏎ (break at end)
This line counter33
wc -l (Linux, macOS, Git Bash)23
Python len(text.splitlines())33
PHP count(file($path))33
JavaScript text.split('\n').length34
Code editors (VS Code, Notepad++)3shows a 4th, empty line number

wc -l counts line-break characters rather than lines, which is why it reports 2 for text without a final break. Once you know the rule, the numbers line up.

Windows (\r\n), classic Mac (\r) and Unix (\n) line breaks are all recognised, even mixed together in one paste, so a list stitched together from different sources still counts correctly.

Lines are not always records: a note on CSV files

A line counter counts lines of text. It doesn't understand file formats. In a CSV file, a cell wrapped in quotes is allowed to contain a line break, for example an address or a note. That single record then spreads over two or more lines.

For example, a CSV with a header row and two records, where one quoted note contains a line break, shows 4 lines here even though it holds only two data records. Also remember that the header row is a line too, so subtract one when you want the number of data rows. For exact record counts in complex CSV files, open them in a spreadsheet and check the row number of the last record.

What the clean-up buttons do

Remove blank lines

Deletes empty lines and lines made only of spaces or tabs. Useful for lists pasted from emails and documents, which often have a gap between every item.

Remove duplicates

Keeps the first copy of each line in its original place and drops later repeats. It follows your Ignore case and Ignore spaces settings. Blank lines are left for the button above.

Sort A–Z or Z–A

Uses natural order, so "Item 1, item 2, item 10" sort the way a person would expect instead of 1, 10, 2. Capital and small letters are treated alike, and blank lines go to the bottom.

Number the lines

Adds "1. ", "2. ", "3. " in front of each non-empty line and skips blank ones, turning a plain list into a ready-made numbered list.

Trim lines

Strips spaces and tabs from both ends of every line. Run it before importing a list into a system that treats "abc " and "abc" as different values.

Copy, Undo and Clear

Copy puts the whole result on your clipboard. Undo reverses the last button press or Clear. Rewritten text uses standard \n line breaks, which work almost everywhere.

Counting lines in other places

Sometimes the text is already inside another program. These methods give you a line count without leaving it:

For a quick answer, or when you also want duplicates and blanks checked, pasting the text here is usually faster.

Where a line count is useful

Common causes of a wrong line count

Your text stays in your browser while you use this page: the counting and clean-up run on your own device, and nothing you paste is uploaded or saved.

Related free tools

To count words instead of lines, use the Word Counter. The Character Counter checks text against platform limits, and the Case Converter fixes capital letters across a whole list at once. Once a list is clean, you can draw a winner with the Spin Wheel. For giveaways, see our guide on picking winners fairly, and read how a random list picker makes everyday choices easier.

Frequently asked questions

How do I count the number of lines in a text?
Paste the text into the box at the top of this page. The total line count appears immediately, together with non-empty, blank, unique and duplicate lines.
Why does wc -l show one line fewer than this tool?
wc -l counts line-break characters, not lines. If the last line has no line break after it, wc -l doesn't count it, while this tool does. With a final line break, both give the same number.
Does a line break at the end of the text add a line?
No. One line break after the last item only finishes that line. A second line break at the end adds one blank line, which shows up in the blank lines figure.
Is a line with only spaces counted as blank?
Yes. Lines containing only spaces or tabs count as blank lines and are deleted by the Remove blank lines button.
How do I remove duplicate lines but keep the order?
Click Remove duplicates. The first copy of each line stays where it was and later copies are deleted, so the order of your list doesn't change. Sort afterwards only if you want alphabetical order.
Why are two lines that look the same not counted as duplicates?
They differ in a way you can't easily see, usually capital letters or spaces. Tick Ignore case, and keep Ignore spaces at line ends switched on, then the counter treats them as the same entry.
Can I count rows in a CSV file with this tool?
Yes, for simple CSV files. Subtract one for the header row. If any quoted cell contains a line break, that record spans several lines, so the line count will be higher than the number of records.
How do I count lines inside a single Excel cell?
Use =IF(A1="",0,LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1). It counts the Alt+Enter line breaks in cell A1 and adds one. The same formula works in Google Sheets.
How many lines can I paste?
There is no fixed limit. Lists of many thousands of lines work smoothly; extremely large pastes depend on your device's memory and browser.
Is my list sent anywhere?
No. The counting and clean-up run in your browser, and the text you paste is not uploaded or stored.

More free writing tools

Hand-picked articles on the same topic as this tool, with limits, examples and tips.

Latest Articles & Guides

Read our newest tutorials, guides and helpful articles from RandomCount.

View All Articles

AK

About the Author

· Founder & Creator of RandomCount

Ashish K. creates and reviews the free online tools and educational guides on RandomCount. RandomCount focuses on making everyday digital tasks easier through practical tools, clear instructions and useful examples.

This page explains how lines, blank lines and duplicate lines are counted, and how to clean up lists.

More from Ashish K. →