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?
views:
150answers:
1
+5
A:
Try this zwc script:
#! /bin/bash --
for F in "$@"; do
echo "$(zcat -f <"$F" | wc) $F"
done
pts
2009-05-10 20:49:41
It should be "echo "$(zcat -f <"$F" | wc -l) $F"
Reef
2009-05-10 22:21:36
Thanks, this works great.
pseinstein
2009-05-10 23:03:49
or $(zgrep -c "" $F)
Chas. Owens
2009-05-11 00:21:42