Problem in piping the file(s) content from zip files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in piping the file(s) content from zip files
# 1  
Old 09-11-2009
Problem in piping the file(s) content from zip files

Hi friends

I have a zip file 1.zip which contains three text files a.txt b.txt c.txt
I want to grep some text(keyword) in those 3 files without extracting all the three files to a local directoryusing the command,
unzip -p 1.zip |grep "search text" >result.txt


The Output file is looking like this:
Search text from a.txt
Search text from b.txt
Search text from c.txt

But i need the following output:
a.txt: Search text from a.txt
b.txt: Search text from b.txt
c.txt: Search text from c.txt


I mean I need the file identity in each matching text string from each file.
I hope all of you understood the problem statement.
Please send me the modified command.Regards
Sidda
# 2  
Old 09-11-2009
Quote:
Originally Posted by ks_reddy
Code:
 
unzip -p 1.zip |grep "search text"  >result.txt

Ad hoc (untested):

Code:
unzip -p 1.zip | grep --with-filename 'search text'  > result.txt

Remark: as stated in the according man page, 'unzip -p' means "unzip to stdout / pipe". Therefore, depending on it's contents, it might be more efficient to unzip the archive "once and (for) all", then grep through the resulting (temporary) directory (?).
# 3  
Old 09-11-2009
Thanks Dr. House. I got it.. It works well with new command mentioned by you.
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

Grep on zip file problem

Hi All, I'm stuck with this issue when I try to display the searched string into a compressed file. More exactly when I run this script for f1 in $(find dir1 -type f -print); do gunzip -c $f1 | grep -n "gio" | awk -F":" '{print $1-1 "," $1 "p"}' | xargs -i sed -n {} $f1 ; done returns... (3 Replies)
Discussion started by: gio1234
3 Replies

5. Shell Programming and Scripting

Rename files in ZIP file

Hi guys, I want to change the name of zip file and the files in zip. eg. there are two zip files 100_ABC_20101020.zip 101_ABC_20101020.zip 100_ABC_20101020.zip | --100_A_20101020.txt --100_B_20101020.txt --100_C_20101020.txt 101_ABC_20101021.zip | ... (0 Replies)
Discussion started by: ambious
0 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Zip recursive content of folder when (not current directory=

Hi, Is there a way to zip the content (recursively) of a folder other then the current directory, and keep the directory structure intact? Example: /var/tmp/myfolder ----------------- file1 ----------------- file2 ----------------- folder1 ------------------------ file3 Now I want... (3 Replies)
Discussion started by: jimih
3 Replies

8. 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

9. Shell Programming and Scripting

zip all of files except last file

hi, I try to write a script to zip archivelog files in arch fold except not zip last archivelog file since it database may be still using the last file here is my script. when I run the script, I get error messages. could you please advise/correct my script in detail what it could be wrong, I am... (9 Replies)
Discussion started by: percvs88
9 Replies

10. 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
Login or Register to Ask a Question