Free Line Counter

Paste any text and instantly see how many total lines it has, plus a breakdown of non-empty, unique, and duplicate lines. Everything runs in your browser, so nothing is uploaded.

6
Total lines
5
Non-empty lines
4
Unique lines
1
Duplicate lines

Summary

Total lines: 6
Non-empty lines: 5
Unique lines: 4
Duplicate lines: 1

Quick answer

To count lines, paste your text into the box. The tool splits the text on every newline character to get the total line count, then ignores blank lines for the non-empty count, uses a Set to find unique lines, and subtracts unique from non-empty to report duplicates. Results update live as you type.

Formula & method

Total lines

total = number of segments after splitting the text on the newline character
  • total count of all lines, including blank ones

Non-empty lines

nonEmpty = count of lines that contain at least one non-whitespace character after trimming
  • nonEmpty lines with visible content

Unique lines

unique = size of the Set built from all non-empty lines
  • unique distinct non-empty lines

Duplicate lines

duplicates = nonEmpty - unique
  • duplicates repeated lines beyond the first occurrence of each distinct line
  • nonEmpty lines with visible content
  • unique distinct non-empty lines

The line counter splits your pasted text on the newline character (\n) to produce an array of lines, so the total line count equals the number of items in that array. A trailing newline therefore does not add an extra phantom line beyond what you typed, while a blank line in the middle still counts toward the total. Non-empty lines are those that contain at least one non-whitespace character after trimming, so lines made up only of spaces or tabs are treated as empty. Unique lines are computed by inserting each non-empty line into a JavaScript Set, which keeps only one copy of each distinct value; the size of the Set is the unique count. Duplicate lines are then derived as non-empty minus unique, which tells you how many extra repeated lines exist beyond the first occurrence of each distinct line. All counting happens client-side in plain JavaScript, so even very large pastes stay private and never leave your device.

Examples

Example 1: Simple list with a repeat and a blank line
Input
apple banana apple orange
Result
Total: 5, Non-empty: 4, Unique: 3, Duplicate: 1
Why
Splitting on newline gives 5 segments [apple, banana, apple, (blank), orange]. The blank line is excluded, leaving 4 non-empty lines. Distinct non-empty values are apple, banana, orange = 3 unique. Duplicates = 4 - 3 = 1 (the second apple).
Example 2: No duplicates
Input
red green blue
Result
Total: 3, Non-empty: 3, Unique: 3, Duplicate: 0
Why
Three segments, none blank, so non-empty is 3. All three values are distinct, so unique is 3 and duplicates = 3 - 3 = 0.
Example 3: Multiple repeats and whitespace-only line
Input
cat cat cat dog
Result
Total: 5, Non-empty: 4, Unique: 2, Duplicate: 2
Why
Five segments total. The line with only spaces is treated as empty after trimming, so non-empty is 4 (three cats and one dog). Distinct values are cat and dog = 2 unique. Duplicates = 4 - 2 = 2 (the two extra cats).

When to use this tool

  • Cleaning up a list (emails, URLs, keywords) and you want to know how many entries are repeated before deduplicating.
  • Checking that a generated or exported file has the exact number of records you expect, line by line.
  • Quickly auditing pasted logs, CSV rows, or config files to see total versus meaningful (non-empty) line counts.

Common mistakes

  • Assuming a final newline adds an extra line. Splitting on the newline character means a single trailing newline creates one empty segment at the end; this tool counts that empty segment toward the total but not toward non-empty lines.
  • Expecting lines that contain only spaces or tabs to count as content. They are trimmed first, so whitespace-only lines are treated as empty and excluded from the non-empty, unique, and duplicate figures.
  • Thinking duplicate count equals the number of repeated values. It is the number of extra repeated lines: three identical lines count as two duplicates, because only copies beyond the first occurrence are counted.

Frequently asked questions

How does the line counter define a line?

A line is any segment of text separated by a newline character. The tool splits your input on every newline, so the total line count is simply the number of segments produced, including blank lines that fall between content.

What is the difference between total lines and non-empty lines?

Total lines counts every segment, including blank or whitespace-only ones. Non-empty lines counts only those segments that still contain at least one visible character after trimming surrounding spaces and tabs.

How are unique and duplicate lines calculated?

Unique lines are the distinct non-empty lines, found by adding each non-empty line to a Set so repeats collapse to one. Duplicate lines is non-empty minus unique, which is the number of repeated lines beyond the first appearance of each distinct line.

Does a trailing newline at the end of my text add an extra line?

It adds one empty segment to the total because splitting on the newline character produces a blank final element. That blank does not affect the non-empty, unique, or duplicate counts, since whitespace-only and empty segments are ignored for those.

Are whitespace-only lines counted as content?

No. Lines that contain only spaces or tabs are trimmed to nothing and treated as empty, so they are included in the total count but excluded from non-empty, unique, and duplicate counts.

Is my text uploaded anywhere?

No. All counting runs entirely in your browser using plain JavaScript. Your text never leaves your device and nothing is sent to a server, which makes it safe for sensitive logs or lists.

Sources & references

External references open in a new tab. We are independent and not affiliated with these organizations.

  • ✓ Free to use
  • ✓ No sign-up required
  • Runs entirely in your browser — nothing is uploaded.
  • ✓ Formula and method shown above

Provided “as is” for general information only — results may be inaccurate, so verify before you rely on them. No warranty; use at your own risk.

Built and reviewed by HIFreeTools against the formula shown above and any authoritative references cited on this page. See our methodology and editorial standards.

Related tools

Embed this tool on your site

Free to embed, no sign-up. Paste this code where you want the line counter to appear: