How to count the number of lines in a gzip file?
wc -l
can be used to get the number of lines from a normal file but what if it is a .gz file ??
Asked
Active
Viewed 4,101 times
2

Govind Kailas
- 2,645
- 5
- 22
- 24
1 Answers
4
Try to do this, It may help You.
gzcat filename.ZIP|wc -l

subodh
- 6,136
- 12
- 51
- 73
-
This would be fine with small files, but my gzip file is ~16gb. thanks ,but any other thoughts ?? – Govind Kailas Jan 10 '12 at 08:20
-
@GovindKailas : aix is OS that famous for its lack of special featured utilities. In any case, I don't think any of the GNU utilities would help with this problem. This may sound glib, but if you can't spare the time to unzip it, then maybe you shouldn't spend the time ziping it OR you shouldn't be zipping such large files as one, think 'small is beautiful' ;-). – shellter Jan 10 '12 at 17:30
-
2@GovindKailas: Regardless you're going to have to expand the file out to count lines. Lines are counted as text surrounding a newline (\n) character. gzip compression (DEFLATE) works in byte blocks, completely ignoring anything about arbitrary lines. If you want to cache the number of lines in the file, count them before you compress it and save that data elsewhere. Or count lines as you build the file in the first place. – CoreyStup Jan 10 '12 at 23:11