File count lines in a compressed file

count lines in a compressed file ( Unix)

My Zip file having multiple files, without ever writing the (decompressed) file to disk., how i can check the line counts for each of the file

I tried using zcat <*.zip> | wc -l , this is reading only the first file and ignoring other files in the Zip folder . Appreciate if any one can provide the solution for this.

Without knowing what OS you're using we can only make guesss about which utilities associated with zip are installed on your system. On many systems the following might work for you:

unzip -Z1 file.zip | while IFS= read -r file
do	printf '%8d %s\n' "$(unzip -p file.zip "$file"|wc -l)" "$file"
done

where you replace file.zip in both places about with the pathname of your Zip file. This will produce output similar to the output produced by:

wc -l file...

where file... is replaced by the pathnames of the files in your Zip file, except that the total line produce by wc will be omitted.

1 Like

Thanks a lot Don, It worked. Thanks for your time and Help.

How to Read Multiple Files in a Loop ?

My input file having 10 ZIP files.

Happy Holidays.

I don't know what you mean by: "My input file having 10 ZIP files."
Assuming that you mean that you have ten Zip files in your current working directory all with names ending in .zip , you could try putting my earlier code in a loop something like:

for zip in *.zip
do	printf 'Processing Zip file "%s"\n' "$zip"
	unzip -Z1 "$zip" | while IFS= read -r file
	do	printf '%8d %s\n' "$(unzip -p "$zip" "$file"|wc -l)" "$file"
	done
done

If you mean that you have a file (in this example named ziplist.txt that contains pathnames of your Zip files with one Zip file on each line in that file, it would be something more like:

while IFS= read zip
do	printf 'Processing Zip file "%s"\n' "$zip"
	unzip -Z1 "$zip" | while IFS= read -r file
	do	printf '%8d %s\n' "$(unzip -p "$zip" "$file"|wc -l)" "$file"
	done
done < ziplist.txt