find - exec grep question

This is a discussion on find - exec grep question within the Unix and OS Discussions forums in Database and Unix Discussions category; markg9-at-yahoo.com wrote: > I've been trying to search for a text sting in all files on the drive. > The following works , BUT the actual file name is not returned (only > the string occurence is printed). What else do I need??? > > find /opt/icor/fx -exec grep text string {} ; > > Thanks a llot, > Mark > I use often find -type f -print -exec grep {} ; it lists the file found first and then executes the grep which might find the pattern or not. you have then the filename listing group together with the output of grep below. an alternative may be '-ls' ...

Go Back   Database Forum > Database and Unix Discussions > Unix and OS Discussions

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
Reply
  LinkBack Thread Tools Display Modes
  #11  
Old 06-13-2007, 01:15 AM
Default Re: find - exec grep question

markg9-at-yahoo.com wrote:
> I've been trying to search for a text sting in all files on the drive.
> The following works , BUT the actual file name is not returned (only
> the string occurence is printed). What else do I need???
>
> find /opt/icor/fx -exec grep "text string" {} \;
>
> Thanks a llot,
> Mark
>


I use often

find -type f -print -exec grep {} \;

it lists the file found first
and then executes the grep which might find the pattern or not.
you have then the filename listing group together
with the output of grep below.
an alternative may be '-ls' instead of '-print'
-ls lists the file in long format as the 'ls' command does
-print lists only the filename itself

Sven



--
Sven-Olaf Hilmer, Solaris System Engineer
http://www.hilmer-informatik.ch
Reply With Quote
  #12  
Old 06-13-2007, 05:02 PM
Default Re: find - exec grep question

In article <1181663967.935774.73180@z28g2000prd.googlegroups.c om>,
Karoly VEGH wrote:
>On Jun 12, 3:34 pm, mar...@yahoo.com wrote:
>> I've been trying to search for a text sting in all files on the drive.
>> The following works , BUT the actual file name is not returned (only
>> the string occurence is printed). What else do I need???
>>
>> find /opt/icor/fx -exec grep "text string" {} \;

>
>find path/to/wherever -type f | xargs grep lists
>
>this one doesnt even execute grep for every file found, and finds only
>files.


A bad advise.....

better call:

find path/to/wherever -type f -exec "text string" {} +

--
EMail:joerg-at-schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js-at-cs.tu-berlin.de (uni)
schilling-at-fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
URL: http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily
Reply With Quote
  #13  
Old 06-13-2007, 05:10 PM
Default Re: find - exec grep question

On 13 Jun 2007 20:01:47 GMT js-at-cs.tu-berlin.de (Joerg Schilling) wrote:
> In article <1181663967.935774.73180@z28g2000prd.googlegroups.c om>,
> Karoly VEGH wrote:
>>On Jun 12, 3:34 pm, mar...@yahoo.com wrote:
>>> I've been trying to search for a text sting in all files on the drive.
>>> The following works , BUT the actual file name is not returned (only
>>> the string occurence is printed). What else do I need???
>>>
>>> find /opt/icor/fx -exec grep "text string" {} \;

>>
>>find path/to/wherever -type f | xargs grep lists
>>
>>this one doesnt even execute grep for every file found, and finds only
>>files.

>
> A bad advise.....
>
> better call:
>
> find path/to/wherever -type f -exec "text string" {} +

^^^
grep

Also not that great. If the last grouping is 1 file you won't get the
filename for that result.

1. find -exec grep -l {} +
2. find -exec grep {} /dev/null +
3. grep -r (for GNU grep)

-frank
Reply With Quote
  #14  
Old 06-13-2007, 05:11 PM
Default Re: find - exec grep question

Joerg Schilling wrote:
> In article <1181663967.935774.73180@z28g2000prd.googlegroups.c om>,
> Karoly VEGH wrote:
>> On Jun 12, 3:34 pm, mar...@yahoo.com wrote:
>>> I've been trying to search for a text sting in all files on the drive.
>>> The following works , BUT the actual file name is not returned (only
>>> the string occurence is printed). What else do I need???
>>>
>>> find /opt/icor/fx -exec grep "text string" {} \;

>> find path/to/wherever -type f | xargs grep lists
>>
>> this one doesnt even execute grep for every file found, and finds only
>> files.

>
> A bad advise.....
>
> better call:
>
> find path/to/wherever -type f -exec "text string" {} +


Someone who can say when '+' become available in Solaris find ???
Reply With Quote
  #15  
Old 06-13-2007, 05:15 PM
Default Re: find - exec grep question

In article ,
Thommy M. wrote:
>Darren Dunham wrote:
>> "Thommy M. Malmström" wrote:
>>> markg9-at-yahoo.com wrote:
>>>> I've been trying to search for a text sting in all files on the drive.
>>>> The following works , BUT the actual file name is not returned (only
>>>> the string occurence is printed). What else do I need???
>>>>
>>>> find /opt/icor/fx -exec grep "text string" {} \;
>>>>

>>
>>> Another approach maybe. It's faster too

>>
>>> find /opt/icor/fx | xargs grep "text string"

>>
>> It's no faster than the '+' version shown, and it will fail by default
>> on filenames that have spaces or newlines in the name.

>
>Well, the '+' thing is a little new to me...



It is more than 15 years old now......

--
EMail:joerg-at-schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js-at-cs.tu-berlin.de (uni)
schilling-at-fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
URL: http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily
Reply With Quote
  #16  
Old 06-13-2007, 05:30 PM
Default Re: find - exec grep question

On Wed, 13 Jun 2007 06:14:52 +0200
Sven Hilmer wrote:

> I use often
>
> find
-type f -print -exec grep {} \;
>
> it lists the file found first
> and then executes the grep which might find the pattern or not.
> you have then the filename listing group together
> with the output of grep below.


It's been a while now that find has the + terminator in addition to the
semi-colon:

find -type f -exec grep {} +

It instructs find to submit as many file names as possible to a single
instance of grep (which then conveniently supplies you with the file
name in front of every match).

--
Stefaan A Eeckels
--
"Technically, Windows is an 'operating system,' which means that it
supplies your computer with the basic commands that it needs to
suddenly, with no warning whatsoever, stop operating." -Dave Barry
Reply With Quote
  #17  
Old 06-13-2007, 05:48 PM
Default Re: find - exec grep question

On Wed, 13 Jun 2007 20:10:38 GMT
"Thommy M." wrote:


>
> Someone who can say when '+' become available in Solaris find ???


It's already available on Solaris 2.6 (I checked it just now). Maybe
even earlier, but I no longer have access to older versions of Solaris.

--
Stefaan A Eeckels
--
You know, it is almost always the case in the real world that something
is "fair" when you like it and "unfair" when you don't.
-- Jeffrey Siegal in gnu.misc.discuss
Reply With Quote
  #18  
Old 06-13-2007, 05:53 PM
Default Re: find - exec grep question

In article <2bYbi.2121$ZA.1212@newsb.telia.net>,
Thommy M. wrote:

>> better call:
>>
>> find path/to/wherever -type f -exec "text string" {} +

>
>Someone who can say when '+' become available in Solaris find ???



It is part of SVr4 since the very beginning.

--
EMail:joerg-at-schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js-at-cs.tu-berlin.de (uni)
schilling-at-fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
URL: http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily
Reply With Quote
  #19  
Old 06-14-2007, 04:12 AM
Default Re: find - exec grep question

Hej Thommy!

It was just missing from the man page.

I filed bug 4382701 against the man page for Solaris 9 in Oct 2000.


Thomas
Reply With Quote
  #20  
Old 06-14-2007, 05:38 AM
Default Re: find - exec grep question

Stefaan A Eeckels writes:

>On Wed, 13 Jun 2007 20:10:38 GMT
>"Thommy M." wrote:



>>
>> Someone who can say when '+' become available in Solaris find ???


>It's already available on Solaris 2.6 (I checked it just now). Maybe
>even earlier, but I no longer have access to older versions of Solaris.



The source code suggests it was already in 2.0.

But it wasn't documented until much later.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 07:27 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.