The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep Log file cbo0485 UNIX for Dummies Questions & Answers 1 05-27-2008 11:24 PM
grep from file jaydeep_sadaria Shell Programming and Scripting 2 04-10-2008 12:03 PM
grep file ali560045 Shell Programming and Scripting 0 01-10-2008 07:51 AM
How to grep a number in a file to find them in another file ahjiefreak Shell Programming and Scripting 7 12-12-2007 06:01 AM
grep for a tar File steiner UNIX for Advanced & Expert Users 1 07-19-2004 11:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-30-2008
deepakwins deepakwins is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 39
grep throught Zip file.

Hi,

There are serveral files available in a folder.
1. Is there any way I get the list of zip files which contain abc.txt
2. Is ther any way, I get the list of zip file which contain a file which inturn content like "First line of file"

There are lot of huge zip files.

Kind Reards
Deepak
  #2 (permalink)  
Old 01-30-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
1:
Code:
for file in *.zip ; do if unzip -qq -l $file | awk '{ print $4 }' | grep filename_to_look_for > /dev/null ; then echo $file ; fi ; done
2:
Code:
for file in *.zip ; do if unzip -p $file | strings | grep searchstring > /dev/null ; then echo $file ; fi ; done
If you want to get the file within the zip, it'll be a slower search but you can do this:
Code:
#!/bin/su
$searchstring=$1
for zipfile in *.zip
do
  unzip -qq -l $zipfile | awk '{ print $4 }' | while read file
  do
    if unzip -p $zipfile $file | grep $searchstring > /dev/null
    then
      echo "$zipfile / $file"
    fi
  done
done
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0