Skip to content
UniKit

Large file line counter

Count lines, blank lines, non-blank lines, characters, UTF-8 bytes, the longest line and the average line length in huge text files by reading them in 4 MiB chunks (a 50 MB file takes well under a second). Batch multiple files, pick UTF-8 / GBK / Big5 / UTF-16 and detect BOMs — all locally in the browser.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Paste text (optional, for quick checks)

Pasted text is counted as UTF-8 under the pseudo name pasted.txt. For large files use the picker below — it reads in chunks and never holds the whole file.

Read in 4 MiB chunks and counted on the fly; nothing is uploaded. Up to 2 GB per file and 30 files per run.

Counts

Line rules: LF / CRLF / CR all end a line, and a trailing newline does not add an extra line.

Pick a file or paste text to see the counts

What this tool does

  • Check the total line count of a 50 MB–GB log, CSV or SQL dump before splitting or sampling it
  • Compare line counts, blank lines and longest lines between two text files to locate a difference
  • Measure characters and UTF-8 bytes of an export to estimate upload, database or attachment size

Example

Input

one
two

中文😀

Output

file	size	lines	blank	non-blank	characters	utf8	longest	average
pasted.txt	20	4	1	3	9	20	3	2.25

4 lines including 1 blank line; "中文😀" counts as 3 characters (code points) and 10 UTF-8 bytes, so the whole text has 9 characters and 20 bytes.

Frequently asked questions

Can it really count hundreds of megabytes? What about memory?

Counting is chunked: it reads 4 MiB at a time, decodes the chunk with a streaming TextDecoder and updates the counters immediately, keeping only the line that has no newline yet. Memory use is therefore independent of file size (worst case: the length of the longest single line). Measured here (Node 26 / Apple Silicon) a 52 MB / 1,000,000-line text took about 0.2 seconds with a peak heap near 90 MB, most of which was the source string itself. The UI caps a file at 2 GB and 30 files per run; in practice the slowest part is the browser reading bytes from disk, and progress is shown.

How are lines counted, and does it match wc -l?

LF, CRLF and a lone CR each end a line, and a trailing newline does not add an extra line: `"a\nb\n"` is 2 lines and `"a\nb"` is also 2 lines; an empty file is 0 lines. That matches the usual `wc -l` result (`wc -l` counts newline characters, so a final line without a newline is not counted by wc) — for a file without a trailing newline the two numbers differ by one. A blank line is one containing only spaces, tabs, vertical tabs, form feeds or the ideographic space U+3000.

What happens if I pick the wrong encoding?

UTF-8 is the default and a BOM at the start of the file is detected and skipped (for UTF-16 the BOM decides the byte order). With the wrong choice: GBK is ASCII-compatible and UTF-16 line feeds still contain 0x0A, so the line count is usually still right, but characters, longest line and the displayed text will be wrong (decoding UTF-16 as UTF-8 also adds a NUL character per line). If the runtime does not support the selected decoder (rare), the tool falls back to UTF-8 and shows a warning.

What is the difference between characters, bytes and size on disk?

Characters are Unicode code points (an emoji counts as 1, newlines excluded); UTF-8 bytes is the size of the decoded text re-encoded as UTF-8 including newlines; "size on disk" comes straight from the file's file.size and is the real byte count of the file. Differences are expected: one CJK character is 1 character and 3 UTF-8 bytes, a UTF-16 file is about twice its character count on disk, and a BOM counts towards the file size but not the character count.

Are my files uploaded, and how does this compare to wc?

Nothing is uploaded. Reading uses the local File API: the bytes are decoded and counted in memory, never sent over the network and never written to disk. Command-line `wc -l -c file` is faster and better for scripted batch jobs; this tool needs no setup, shows blank lines, longest line and average length, and handles GBK or UTF-16 files.

Keywords:line countercount lines in large filewc -lUTF-8 BOM

Related tools