delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/05/23/19:22:31

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-Id: <5.1.0.14.2.20020523160826.0268a7a8@pop3.cris.com>
X-Sender: rrschulz AT pop3 DOT cris DOT com
Date: Thu, 23 May 2002 16:21:43 -0700
To: macarthy AT iol DOT ie, cygwin AT cygwin DOT com
From: Randall R Schulz <rrschulz AT cris DOT com>
Subject: Re: Searching for Zipped file contain a file
Mime-Version: 1.0

Justin,

Sorry, that was not a correct answer, since you're invoking grep on the 
standard input.


Create a shell script that searches one file at a time and include the -H / 
--with-filename option to grep. It'll be somewhat slower, but presumably 
this isn't something you'll do frequently.


     find /c -iname '*.jar' -exec checkPresence SAXParser.class '{}' \;


Where "checkPresence" is this file:

-==-
#!/bin/sh

unzip -l "$2" |grep -H "$1" >/dev/null && echo "$2"
-==-

You can make checkPresence accept multiple file names, which will speed 
things considerably:

-==-
#!/bin/sh

pattern="$1"
shift

for arg; do
         unzip -l "$arg" |grep -H "$1" >/dev/null && echo "$2"
done
-==-

now you can do this:

     checkPresense SAXParser.class $( find ... )

The only possible problem here is if there are too many files output by 
find. In that case, use xargs.


Randall Schulz


-==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-


Justin,

[ This isn't Cygwin-specific. It's just a GNU grep question. ]


% grep --help
...
   -H, --with-filename       print the filename for each match
...



Randall Schulz
Mountain View, CA USA




At 16:09 2002-05-23, Justin (Home Office) wrote:
>Hi I'm looking for a quick bash script to get a list of all the *.jar 
>files that have the file SAXParser.class in them
>
>find /c -name '*.jar' -exec unzip -l '{}' \; | grep 'SAXParser.class' > 
>/c/results.txt
>
>This nearly does it, but I really want '{}' (ie the jar filename) Any bash 
>gurus have an idea?
>
>
>Thanks, J


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019