About the Line Counter
This line counter tells you how many lines are in a block of text, and how many of them are blank, non-empty, unique or repeated. It also reports the longest line, the average length of non-empty lines and a line-by-line table, so you can check a file before importing it or spot an unexpected empty row.
Developers use it to count lines of code or log entries, data analysts to check how many rows a CSV or list has before pasting it into a spreadsheet, writers and poets to count lines in a poem or script, and marketers to check keyword or email lists for blanks and duplicates. Lines split at any line ending — Windows (CRLF), Unix (LF) or old Mac (CR).
By default a trailing line break at the very end does not add an extra empty line, which matches how most editors and the Unix wc -l command count, and lines that contain only spaces or tabs count as blank. You can change both behaviours with the toggles.
With the default inputs, the total lines is 7. Change any value above to recalculate instantly.
How to use the line counter
- 1Paste your text, list, code or CSV into the box.
- 2Choose whether whitespace-only lines count as blank.
- 3Decide whether a final line break adds an empty line.
- 4Read the totals and scan the table for blanks and duplicates.
Formula and method
The text is split at every line ending: CRLF (Windows), LF (Unix, macOS) or a lone CR (classic Mac). If the text ends with a line break, the empty piece after it is dropped unless you choose to count it, so "a\nb\n" is 2 lines, the same as wc -l and most code editors. An empty box is 0 lines; any text without a line break is 1 line. Note that wc -l literally counts newline characters, so for text whose last line has no final line break ("a\nb") it reports one fewer line (1) than this tool and your editor (2).
A line is blank when it is empty — or, with the default setting, when it contains only spaces or tabs. Non-empty lines are compared exactly (case and spacing matter) to count unique and duplicate lines. Line length is measured in characters (Unicode code points), and the average is taken over non-empty lines only. Words are runs of non-space characters.
- Blank
- Empty, or whitespace-only when that option is on
- Duplicate
- A non-empty line identical to an earlier one
Worked examples
A shopping list with gaps and a repeat
The default list has 7 lines (the final line break does not add one). One line is empty and one holds only spaces, so 2 are blank and 5 have content. "apples" appears twice, leaving 4 unique lines. Lengths 6 + 7 + 8 + 6 + 5 = 32 characters over 5 lines give an average of 6.4.
Counting the trailing empty line
With the trailing-line option on, the empty piece after the final line break counts as a third, blank line — the way some editors number the cursor line at the end of a file.
Whitespace-only lines as content
With the whitespace option off, the line of four spaces counts as non-empty, so all 3 lines have content. "FROM users;" is the longest at 11 characters and there are 4 space-separated words.
Frequently asked questions
Does a newline at the end of the text count as a line?+
Not by default. A final line break ends the last line rather than starting a new one, which is how most editors and Git count. (wc -l counts newline characters, so it shows one fewer when the last line has no final line break.) Turn on "Count the empty line after a final line break" if you want it included.
How do I count lines in a file?+
Open the file in any text editor, select all, copy and paste it here. On macOS or Linux you can also run wc -l filename, and in Windows PowerShell (Get-Content filename).Count gives the same result for most files.
Are lines with only spaces counted as blank?+
Yes, by default lines containing only spaces or tabs are treated as blank, since they look empty. Switch the option off if you need them counted as content, for example when whitespace is significant in your data.
How are duplicate lines detected?+
Each non-empty line is compared exactly with the lines before it, so "Apple" and "apple" or a line with a trailing space are treated as different. Use the Remove Duplicate Lines tool to delete repeats.
What is the difference between lines and sentences?+
A line ends at a line break, wherever it falls, while a sentence ends at punctuation such as a full stop. One paragraph can be a single long line containing several sentences. Use the Sentence Counter for sentences.