Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wc gzipped files?

Tags:

linux

unix

I have a directory with both uncompressed and gzipped files and want to run wc -l on this directory. wc will provide a line count value for the compressed files which is not accurate (since it seems to count newlines in the gzipped version of the file). Is there a way to create a zwc script similar to zgrep that will detected the gzipped files and count the uncompressed lines?

like image 549
pseinstein Avatar asked May 10 '09 20:05

pseinstein


People also ask

What are gzipped files?

A GZ file is a compressed archive that is created using the standard gzip (GNU zip) compression algorithm. It may contain multiple compressed files, directories and file stubs. This format was initially developed to replace compression formats on UNIX systems.

Can you concatenate gzipped files?

Files compressed by gzip can be directly concatenated into larger gzipped files.

How do I view .GZ files without extracting?

Just use zcat to see content without extraction. From the manual: zcat is identical to gunzip -c . (On some systems, zcat may be installed as gzcat to preserve the original link to compress .)

How do I view a .GZ file?

Launch WinZip from your start menu or Desktop shortcut. Open the compressed file by clicking File > Open. If your system has the compressed file extension associated with WinZip program, just double-click on the file.


2 Answers

Try this zwc script:

#! /bin/bash --
for F in "$@"; do
  echo "$(zcat -f <"$F" | wc -l) $F"
done
like image 64
pts Avatar answered Dec 07 '22 11:12

pts


You can use zgrep to count lines as well (or rather the beginning of lines)

zgrep -c ^ file.txt
like image 22
Revan Avatar answered Dec 07 '22 11:12

Revan