for file in `ls -t \`find . -name "*.zip" -type f\``; do found=`unzip -c "$file" | grep --color=always "PATTERN"`; if [[ $found ]]; then echo -e "${file}\n${found}\n"; fi done

Grep through zip files

for file in `ls -t \`find . -name "*.zip" -type f\``; do found=`unzip -c "$file" | grep --color=always "PATTERN"`; if [[ $found ]]; then echo -e "${file}\n${found}\n"; fi done

0
By: vladfr
2012-11-12 15:43:15

These Might Interest You

  • Catches .swp, .swo, .swn, etc. If you have access to lsof, it'll give you more compressed output and show you the associated terminals (e.g., pts/5, which you could then use 'w' to figure out where it's originating from): lsof | grep '\.sw.$' If you have swp files turned off, you can do something like: ps x | grep '[g,v]im', but it won't tell you about files open in buffers, via :e [file]. Show Sample Output


    3
    vim -r 2>&1 | grep '\.sw.' -A 5 | grep 'still running' -B 5
    rkulla · 2010-04-17 19:43:35 1
  • short command to find a string in all text files in all subdirectories, excluding all files grep does not deem text files.


    0
    grep -Ir foo *
    libdave · 2009-07-17 15:30:10 2
  • This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for. Show Sample Output


    -5
    ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done
    psytek · 2009-03-20 20:33:36 1
  • Greps located files for an expression. Example greps all LaTeX files for 'foo': locate *.tex | xargs grep foo To avoid searching thousands of files with grep it could be usefull to test first how much files are returned by locate: locate -c *.tex


    -2
    locate searchstring | xargs grep foo
    zimon · 2009-04-16 12:51:24 0
  • The difference between this and the other alternatives here using only grep is that find will, by default, not follow a symlink. In some cases, this is definitely desirable. Using find also allows you to exclude certain files, eg find directory/ ! -name "*.tmp" -exec grep -ni phrase {} + would allow you to exclude any files .tmp files. Also note that there's no need for calling grep recursively, as find passes each found file to grep.


    0
    find directory/ -exec grep -ni phrase {} +
    sanmiguel · 2010-01-28 12:15:24 0
  • Variant of find grep that ignores files with .svn in the name. Useful for searching through a local repository of source code.


    -3
    find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM"
    troelskn · 2009-02-05 10:27:15 3

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: