Work with file inside zip

Hi all,

I`m trying to find 3 files from all zip files in a directory (and its all its subdirectories) recursively, and concatenate them correspondingly along with the filename (possibly path of that file from current directory).

Suppose I have 3 zips

a123.zip 

a234.zip 

a456.zip

and they all have 3 tabular files (among others) named somestring_patter1.txt ,
someotherstring_patter2.txt , and anotherstring_pattern3.txt

then I need to concat all

pattern1.txt

files together along with the filename as one of the columns, similarly for pattern2 and pattern3.

Example inputs for a single pattern :

cat a123.zip ----> somestring1_pattern1.txt

a b
c d

cat a234.zip -----> somestring2_pattern1.txt

e f
g h

cat a456.zip ------> somestring3_pattern1.txt

i j
k l

Output

cat all_pattern1

a123.zip-somestring1_pattern1.txt a b
a123.zip-somestring1_pattern1.txt c d
a234123.zip-somestring2_pattern1.txt e f
a234.zip-somestring2_pattern1.txt g h
a456.zip-somestring3_pattern1.txt i j
a456.zip-somestring3_pattern1.txt k l

Similar outputs for patterns 2 and 3...

This is routine for unzipped folders where a combination of find and awk will do the trick. How do I search files inside zipped folders?

Thanks a lot for your guidance.

Use the zgrep command or zcat file.zip | grep 'pattern'

1 Like

Jim, I think zgrep/zcat is for .gz (gzip'ed) files.?
Suggestion with find and unzip

find . -type f -name "*.zip" -exec unzip -p {} "*pattern1.txt" \;
1 Like