Work with file inside zip


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Work with file inside zip
# 1  
Old 03-19-2015
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

Code:
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
Code:
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

Code:
a b
c d

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

Code:
e f
g h

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

Code:
i j
k l

Output


cat all_pattern1
Code:
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.
# 2  
Old 03-20-2015
Use the zgrep command or zcat file.zip | grep 'pattern'
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 03-21-2015
Jim, I think zgrep/zcat is for .gz (gzip'ed) files.?
Suggestion with find and unzip
Code:
find . -type f -name "*.zip" -exec unzip -p {} "*pattern1.txt" \;

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

4. Shell Programming and Scripting

Rename files that are inside zip file

Hello to all, I have a zip file with any name like FileName.zip, within the zip file there are more than 30 files with different extensions in the following format. FileName_BMN_ROSJ.txt FileName_THEUS.jpg . . . FileName_KWPWP.shx I would like to unzip the file and rename each file... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

5. UNIX for Advanced & Expert Users

Zip file inside Zip file(s)

I've a zip file called Z00.zip and in that file there are 22 more zip files. Each zip file having .txt files nearly 10,000 files. I am trying to unzip all these .txt files in one command line to unzip each .zip file from Z00.zip file. Would like to know whether possible to unzip all sub-zip files... (1 Reply)
Discussion started by: nvkuriseti
1 Replies

6. Shell Programming and Scripting

Searching for a string in .PDF files inside .RAR & .ZIP archives.

Hi, I have got a large number of .PDF files that are archived in .RAR & ZIP files in various directories and I would like to search for strings inside the PDF files. I would think you would need something that can recursively read directories, extract the .RAR/.ZIP file in memory, read the... (3 Replies)
Discussion started by: lewk
3 Replies

7. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

8. Shell Programming and Scripting

grep inside the zip file

i have to grep a particular pattern say "meter number" in 100s of zip files file1.zip : : : : file100.zip how to achive this? cat *.zip | grep "meter number" also i dnt want to unzip and then grep it...... hope i made myself clear. thanks in advance (5 Replies)
Discussion started by: ali560045
5 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question