The UNIX and Linux Forums  

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
find , grep james94538 UNIX for Dummies Questions & Answers 3 10-09-2008 06:03 PM
grep, find or awk? netrom UNIX for Dummies Questions & Answers 4 04-09-2008 02:03 PM
grep and find MEllis5 UNIX for Dummies Questions & Answers 1 04-07-2008 05:16 AM
find then grep flame_eagle Shell Programming and Scripting 7 03-13-2008 08:19 AM
find and grep sarwan High Level Programming 4 04-10-2006 04:05 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 02-01-2001
Registered User
 

Join Date: Jan 2001
Location: The Netherlands
Posts: 4
Unhappy

Quote:
Originally posted by mib
grep -r "string" * will read all files under each directory recursively.

If I use this I get the message 'grep: illegal option --r'.
Forum Sponsor
  #9  
Old 02-01-2001
Registered User
 

Join Date: Jan 2001
Location: The Netherlands
Posts: 4
Unhappy

Quote:
Originally posted by PxT
Which version of Unix does this work on? I have never encountered a grep that works like this. A portable solution is:

find . -exec grep string {} /dev/null \;
It's Sun 4.1, maybe that explains it...
  #10  
Old 02-01-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Quote:
my grep version: GNU grep 2.3
Interesting. This must be a new feature. I have GNU grep v2.0 on my Linux box. Thanks for the info!
  #11  
Old 02-01-2001
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,493
find . -exec grep string {} /dev/null \;

As I recall, there is often a problem using

Code:
find . -exec grep string {} /dev/null \;
I haven't used this in a while, but I recall getting errors because this usage of find also 'finds' directories, binaries, and just about everything else under the sun. Because it finds binaries, directories, etc. it attempts to search them and gets pretty messy.

Code:
find . -type r -exec grep string {} /dev/null \;
Will find only regular files, and not directories, but does not stop the grep from searching large binaries, as I recall. That is why I usually don't use this combo for grepping strings and forgot about this one. I don't recall a switch in find to stop it from 'finding' binary files. Perhaps there is ?
  #12  
Old 02-01-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Well I usually narrow it down a bit. Something like:

find . -name \*.h -exec grep &lt;<I>etc</I>&gt;



Another good one is something like this:

grep &lt;string&gt; `file * | egrep 'script|text' | awk -F: '{print $1}'`

Not perfect, but I've used it a few times. A little more complicated to do recursive this way though...

[Edited by PxT on 02-01-2001 at 11:22 AM]
Google The UNIX and Linux Forums
Closed Thread

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0