Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

find/grep

3 views
Skip to first unread message

Corinna Jaeger

unread,
Sep 8, 1999, 3:00:00 AM9/8/99
to
Hello,
how can I do a grep on all files that my find command has found? I tried
with -exec but I get an error message.

find / -name *.sql -exec grep -i "V_INV_CALC_PRICE_IMP" * {} ;

find: 0652-018 An expression term lacks a required parameter.

Any help appreciated.
Thanks
Corinna Jaeger

justin

unread,
Sep 8, 1999, 3:00:00 AM9/8/99
to
lose the second '*' and put a '\' before the ';' ie escape the semicolon
(command terminator)

Thomas Neumann

unread,
Sep 8, 1999, 3:00:00 AM9/8/99
to
"Corinna Jaeger" <Corinna...@doremovethis.memo.ikea.com> writes:

> Hello,
> how can I do a grep on all files that my find command has found? I tried
> with -exec but I get an error message.
>
> find / -name *.sql -exec grep -i "V_INV_CALC_PRICE_IMP" * {} ;


Try this:

find / -name "*.sql" -print | xargs fgrep -i V_INV_CALC_PRICE_IMP /dev/null


-t


Snogfest Hosebeast

unread,
Sep 8, 1999, 3:00:00 AM9/8/99
to
In article <01bef9f5$d8e45920$a849...@pc743-sode.seurope.ikea.com>,

"Corinna Jaeger" <Corinna...@doremovethis.memo.ikea.com> wrote:
> Hello,
> how can I do a grep on all files that my find command has found? I
tried
> with -exec but I get an error message.
>
> find / -name *.sql -exec grep -i "V_INV_CALC_PRICE_IMP" * {} ;
>
> find: 0652-018 An expression term lacks a required parameter.
>
> Any help appreciated.
> Thanks
> Corinna Jaeger
>
You were *real* close
try:
find / -name "*.sql" -exec grep -i V_INV_CALC_PRICE_IMP {} \;


--
R1, TDM.
Kiwi.
Don't do surgery with a chainsaw unless you're dealing with zombies


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Peter Bennett

unread,
Sep 8, 1999, 3:00:00 AM9/8/99
to

You should also add /dev/null to it, so that the grep will report which
file it found the string in.

so:-
find / -name *.sql -exec grep -i "V_INV_CALC_PRICE_IMP" {} /dev/null \;

Pete.


justin wrote:
>
> lose the second '*' and put a '\' before the ';' ie escape the semicolon
> (command terminator)
>

Nicholas Buckley

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
Hi,

An alias can be useful...

I use:

alias -x rgrep="find . | xargs -n1 grep"

in my .kshrc

I'm sure this can be refined, but it does the job in 90%+ of cases.

rgrep ??? r(ecursive) grep !!!

Cheers,

Nick Buckley
AIX Administrator,
NCM,
Cardiff,
Wales,
United Kingdom
e-mail: nicholas...@ncmgroup.com
(Please note: all newsgroup offerings are made in a personal
capacity and in no way are the responsibility of my employer)

p.s. Did you know that "AIX Operating System" is an anagram of "Mega sexy
partitions" !!!

Snogfest Hosebeast wrote in message <7r63po$n1d$1...@nnrp1.deja.com>...
>In article <01bef9f5$d8e45920$a849...@pc743-sode.seurope.ikea.com>,


> "Corinna Jaeger" <Corinna...@doremovethis.memo.ikea.com> wrote:
>> Hello,
>> how can I do a grep on all files that my find command has found? I
>tried
>> with -exec but I get an error message.
>>
>> find / -name *.sql -exec grep -i "V_INV_CALC_PRICE_IMP" * {} ;
>>
>> find: 0652-018 An expression term lacks a required parameter.
>>
>> Any help appreciated.
>> Thanks
>> Corinna Jaeger
>>

Joerg Bruehe

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
Hi !

Corinna Jaeger schrieb:


>
> Hello,
> how can I do a grep on all files that my find command has found? I tried
> with -exec but I get an error message.
>
> find / -name *.sql -exec grep -i "V_INV_CALC_PRICE_IMP" * {} ;
>
> find: 0652-018 An expression term lacks a required parameter.

The correct ways were already given. Still some remarks:

1) Your approach using 'exec' starts one 'grep' process
per file name found. This is very expensive compared
to the 'xargs' solution which starts as few processes
as possible (by command line length limit).

The speedup will be enormous, the factor depending on
the file name length (shorter names -> more names per
command line -> higher factor).

This holds for any command, for example also for 'rm'.

2) Your approach passes only one file name to 'grep', so
it will not include the file name in the output.

The 'xargs' approach passes many file names, so the
lines found by 'grep' will start with the file names.
Including '/dev/null' ensures that even the last 'grep'
will have at least two file name arguments.

3) Any pattern given as an argument to the '-name' option
should be quoted. If quotes are omitted, the shell will
try to expand the pattern in the current directory;
this will cause false results in different ways:

a) If there are multiple matches, you get a syntax
error of 'find'.
b) If there is a single match, this one name will be
used instead of the pattern.
c) If there is no match, the shell may deny execution
of the command ('csh' behaves that way).

So do not save on quotes, you need them !

Regards,
Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
(speaking only for himself)
mailto: jo...@sql.de

Snogfest Hosebeast

unread,
Sep 9, 1999, 3:00:00 AM9/9/99
to
In article <37D78B2D...@sql.de>,
Joerg Bruehe <jo...@sql.de> wrote:
> Hi !
>

all true, but
find / -name "*.sql" -exec grep -li V_INV_CALC_PRICE_IMP {} \;

i.e including -l in the grep, will also just return the filename

0 new messages