FG
💻 Software

count lines in a compressed file

Fresh5 days ago
Mar 15, 2026127535 views
Confidence Score1%
1%

Problem

if i have a .gz file on unix which has certain number of lines. How could i count the lines on unix without uncompressing it.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: count lines in a compressed file

Low Risk

You can obviously not count newlines if the file is still compressed. But you can decompress to a stream, and count the newlines in that stream, without ever writing the (decompressed) file to disk. That would go something like so: zcat for decompress & cat, wc for wordcount. See man pages for both if you want to know more. EDIT If you do not have zcat, zcat is just another name for .

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment