Count number of lines of .gz files recursively on directory? Count number of lines of .gz files recursively on directory? unix unix

Count number of lines of .gz files recursively on directory?


You were quite there...:

find . -type f -name '*.gz' | xargs zcat | wc -l


gzip -dc *.gz | wc -l

-d decompress-c to STDOUT (not to disk)

or

gzip -dcr * | wc -l

-d decompress

-c to STDOUT (not to disk)

-r recursive (look in directorties)


my directory:

.├── a.gz├── b.gz└── t    └── f.gz

command to echo and count lines of every gz file found:

find . -type f -name '*.gz' -exec bash -c 'echo $1;gunzip -c $1 | wc -l' dummy {} \;

output:

./a.gz5./b.gz6./t/f.gz3

then, in order to obtain a grand total:

echo $((`find . -type f -name '*.gz' -exec bash -c 'gunzip -c $1 | wc -l' dummy {} \;  | paste -sd+`))

output:

14