About Line Counter
A line count answers practical questions. How many rows are in this export? Did that log really produce 4,000 entries? Which line in this config runs past 120 characters and breaks the linter? Paste the text and every line gets a number, with the total, the blank lines and the lines holding text counted separately.
The tool also looks at line length, which a plain total does not. It finds the longest and shortest lines, gives the average, flags every line over a limit you set, and lists the five longest. Pick one from the list and it is selected in the text, ready to edit.
Repeated lines get their own count, which is an early warning that a list contains duplicates before you import it somewhere.
How it works
The text is split at each line break, after converting Windows and old Mac line endings to a single form. A final line break ends the last line and does not start a new one, so a, b and a trailing newline count as 2 lines. This matches how most programs treat a text file, and when it applies the page says so. A number on an editor's status bar can read one higher, because the editor is counting the empty line where the cursor would go.
A line counts as blank if it holds nothing but spaces or tabs. Those lines look empty and can still break a parser, so the page notes how many of the blank lines contain invisible whitespace. Line length is measured in characters as a reader sees them, so one emoji counts as one, and the list shows the first part of each long line.
The numbers beside the text sit in a separate column that scrolls with it, and the box does not wrap, so one number always means one real line. All of this happens in your browser.
How to use Line Counter
- Paste your text into the Your lines box, or press Upload for a text or log file. Try an example shows a short list with a blank line and a duplicate.
- Read the total and the With text, Blank, Longest line and Repeated lines cards.
- Change the number in Flag lines longer than to match your limit. The default is 80.
- Pick a row in the Longest lines list to select that line in the text.
- Use Copy report or Download report when you want a record of the counts.
A short server log
server started
GET /index.html 200
GET /a/very/long/path/to/a/page.html 404
server stopped
Total lines: 6
Non-empty lines: 4
Empty lines: 2
Longest line: line 4, 40 characters
Shortest line: line 6, 14 characters
Average line length: 21.8 charactersLine 5 holds three spaces and still counts as blank. The line break after server stopped ends line 6, so it does not create a line 7. The averages leave blank lines out.
When it helps
- Checking that a CSV export has the row count you expected, before and after cleaning it.
- Finding the line that a code style rule complains about, such as a 100-character limit.
- Counting entries in a list of URLs, email addresses or SKUs pasted from a spreadsheet.
- Sizing a log excerpt before you attach it to a support ticket.
Tips for a better result
- For a CSV with a header row, subtract one to get the number of records. A quoted field containing a line break also counts as a separate line here.
- If the Repeated lines card is above zero, run the list through Remove Duplicate Lines before importing it.
- Set the flag limit to 72 or 80 for email and commit messages, and to whatever your linter uses for code.
- A command line tool will read differently on a file with no final line break, because
wc -lcounts line breaks and not lines. Expect it to show one fewer in that case.
Good to know
- Files are limited to 20 MB, and line numbers stop at 100,000 for speed. The counts still cover the whole text.
- Line length is in visible characters, not display columns. A wide Chinese character counts as 1, although it takes two columns in a terminal.
- It counts lines as stored in the text. It does not know how text will wrap on a page or in a window.
- Tabs count as a single character, whatever width your editor shows them at.
Questions people ask
Why does my editor show one more line than this tool?
Your file probably ends with a line break, and the editor shows an empty numbered line after it, where the cursor can go. No text is on that line, so it is not counted here. The page tells you when a text ends this way.
Does a line with only spaces count as blank?
Yes. It counts under Blank, and a note says how many blank lines contain hidden spaces or tabs. That helps when a line that looks empty is what your import is failing on.
Can I count the lines in a code file?
Yes, upload it or paste it. Comment lines are counted like any other line, because the tool does not read programming languages. With text gives you a quick approximation of lines of code.
What to use next
- Remove Empty Lines: to take out the blank lines once you have counted them.
- Sort Lines: to put a counted list in order.
- Word Counter: when you need words and reading time and not line figures.
Last reviewed . Read our editorial policy.