Skip to content
MegaRows

CSV row counter: count the rows in any CSV file

Find out how many rows are in a CSV, TSV or TXT file, even one with tens of millions of lines. Free, instant, and the file stays on your device.

Instant row counter

Count the lines in a CSV, TSV or TXT file of any size.

Runs on your device

Drag and drop a file here

CSV, TSV or TXT, any size. Millions of lines are fine.

Your file never leaves your device. It is read by your browser in a background thread. Nothing is uploaded.

How to count rows in a CSV file

  1. Choose your file. Drag a CSV, TSV or TXT file onto the counter, or click “Choose a file”. Any size works, including files far too big for Excel.
  2. Let it count. Your browser streams the file through a background thread and counts every line. A progress bar shows how far it has got, and you can cancel at any time.
  3. Read the result. You get the number of lines, the delimiter, the number of columns in the first line, the file size and the time taken. Subtract one for the header line to get the number of data rows.

Lines, rows and records: what the number means

The counter reports physical lines: every line break starts a new line, and a final line without a trailing line break still counts. For most CSV files, lines and rows are the same thing, with a few exceptions worth knowing:

  • The header line. Most CSV files start with a line of column names. If yours does, the number of data rows is the line count minus one: a file with 1,001 lines holds a header and 1,000 records.
  • Line breaks inside quoted values. CSV allows a field to contain a line break if the field is wrapped in double quotes, for example a multi-line address or comment. Such a record spans two or more lines, so the line count is higher than the record count. A full CSV parser, like the one behind the upcoming MegaRows viewer, counts records instead.
  • Blank lines count as lines too, which matters if an export ends with a few empty lines.

Here is a small example. The counter reports 4 lines, but the file holds a header and only 2 records, because Bob’s comment spans two lines:

id,name,comment
1,Alice,"Called on Monday"
2,Bob,"Line one
line two"

Windows (CRLF) and macOS or Linux (LF) line endings are both counted correctly. Very old Mac files that use a bare carriage return (CR) as the line break are rare today and are reported as a single line.

Built for very large files

The counter never loads the whole file into memory. Your browser hands it over in small chunks, a background thread (a Web Worker) counts the line breaks in each chunk and then lets it go, so memory use stays low however big the file is. Because the work happens off the main thread, the page stays responsive and you can cancel at any time.

In our tests on a recent laptop, a 10-million-line CSV of just over 400 MB is counted in about 0.6 seconds. Speed depends mostly on your disk and browser, so slower machines take longer, but there is no upload to wait for and no size limit to hit. If your file is too big for Excel, our guide on how to open a CSV file that’s too big for Excel walks through what to do next.

Other ways to count rows in a CSV

If you prefer the command line or need to count rows in a script, these work well:

macOS and Linux: wc -l

wc -l data.csv

Fast and built in. wc counts line-break characters, so it reports one less than the real number when the last line has no trailing line break.

Windows: PowerShell or Command Prompt

# PowerShell: streams the file, so it copes with big files (use the full path)
[Linq.Enumerable]::Count([IO.File]::ReadLines("C:\data\data.csv"))

# Command Prompt
find /c /v "" data.csv

(Get-Content data.csv).Count also works, but it reads the whole file into memory first, which gets slow beyond a few hundred megabytes.

Python

# Lines, like the counter above
with open("data.csv", "rb") as f:
    lines = sum(1 for _ in f)

# Records (handles quoted line breaks), header excluded
import pandas as pd
records = sum(len(chunk) for chunk in pd.read_csv("data.csv", chunksize=1_000_000))

Reading in chunks keeps pandas from loading a huge file into memory all at once. A plain len(pd.read_csv("data.csv")) is fine for smaller files.

Excel

Open the file and press Ctrl+End to jump to the last used row. This only works up to Excel’s limit: if the last row is 1,048,576, the file was almost certainly cut off and holds more rows than Excel shows.

Frequently asked questions

How do I count rows in a CSV file without opening it?

Use a line counter instead of a spreadsheet. The row counter on this page reads the file in your browser without loading it into a grid, so it works for files of any size. On the command line, wc -l (macOS and Linux) or find /c /v "" (Windows) do the same job.

Is there a maximum number of rows in a CSV file?

No. CSV is plain text, so the format itself has no row limit. The limits come from the programs that open it: Excel shows at most 1,048,576 rows per sheet, and Google Sheets allows 10 million cells per spreadsheet.

Why is the line count one higher than the number of records?

Because the header line is counted too. A file with a header line and 1,000 records has 1,001 lines. If some values contain line breaks inside quotes, the difference is larger.

Is my file uploaded?

No. The file is read by your browser in a background thread on your own device and is never sent anywhere. You can confirm this in the Network tab of your browser’s developer tools.

Does it work with TSV, TXT and semicolon-separated files?

Yes. It counts the lines in any plain-text file and detects comma, semicolon, tab and pipe delimiters to report the number of columns in the first line. Compressed files such as .zip or .gz need to be extracted first.

How fast is it?

In our tests on a recent laptop, a 10-million-line CSV of just over 400 MB takes about 0.6 seconds. Speed depends mostly on your disk and browser, so slower machines take longer.

Can I count rows in an Excel (.xlsx) file?

Not yet. The counter reads text-based files such as CSV, TSV and TXT. Excel (.xlsx) support is coming soon. In the meantime, Excel itself shows the last row number when you press Ctrl+End, up to its limit of 1,048,576 rows.

Coming soon to MegaRows: Large CSV viewer · Charts with statistics · CSV, Excel, JSON and PDF converters · Split, merge and compare.

MegaRows processes files locally in your browser. Read our privacy statement for details.

Send feedback

Found a bug, missing a feature or just want to say hi? We would love to hear from you.

Type
0 / 5,000

We never receive your files. Sent with your message: page /, version 0.1.0.