How to unzip only the first few lines of a zip archive?
6,745
This simple pipe-script works for me:
zcat a.zip | head -n 10
Here:
zcat a.zip
- unpacks zip-archive and sends its contents to standard output|
pipeszcat
output tohead
inputhead -n 10
- shows first 10 lines from its standard input
Author by
yukashima huksay
Apparently, that user prefers to keep an air of mystery about them.
Updated on September 18, 2022Comments
-
yukashima huksay over 1 year
I have a zipped text file
a.zip
I want to read the first 10 lines of it. Is it possible to do that without unzipping the whole file? -
yukashima huksay over 6 yearsthis unzips the whole file.
-
PerlDuck over 6 years@yukashima I'd guess it depends on the size of
a.zip
. Whenhead
terminates (after printing 10 lines) thezcat
(which isgzip -dc
behind the scenes) should receive a SIGPIPE and stop unzipping. -
Xen2050 over 6 years@yukashimahuksay How do you know it unzips the whole file? I think all zip files keep the file list at the end of the archive, maybe it's just reading the whole file but not actually unzipping it
-
user27164 over 3 yearsI can confirm by example that it does not unzip the whole file as intended.
zcat verybigfile.zip | head -10
prints the first 10 lines immediately. A full unzip would take ca. 10 minutes.