Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use grep in .zip file

Tags:

linux

shell

There are 3 files a.csv,b.csv,c.csv zipped as abh.zip, now is it possible to execute grep command on abh.zip (is there any wild card by which only grep run for c.csv file inside zip).

like image 804
champs Avatar asked Jun 17 '15 07:06

champs


2 Answers

If you have zipgrep (which, AFAIK, is shipped with the zip utilities), then you can simply do

zipgrep "pattern" abh.zip c.csv

zipgrep supports most of the same basic options as vanilla grep.

Alternatively, if you don't have zipgrep but you have unzip, you can do

unzip -p abh.zip c.csv | grep "pattern"

which unzips the file to a pipe (-p) then sends it to be grepped.

like image 75
nneonneo Avatar answered Oct 20 '22 03:10

nneonneo


you can run zipgrep command with pip operator as below.then you can only set name"

zipgrep "name" abh.zip | grep c.csv

like image 20
Kasun Rathnayaka Avatar answered Oct 20 '22 04:10

Kasun Rathnayaka