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?
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.
Files compressed by gzip can be directly concatenated into larger gzipped files.
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 .)
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.
Try this zwc script:
#! /bin/bash --
for F in "$@"; do
echo "$(zcat -f <"$F" | wc -l) $F"
done
You can use zgrep
to count lines as well (or rather the beginning of lines)
zgrep -c ^ file.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With