find & grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find & grep
# 8  
Old 02-01-2001
Data

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'.
# 9  
Old 02-01-2001
Data

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
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
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
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]
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

2. Shell Programming and Scripting

How do i find "&variable[0]" using grep -r?

Guys, i've got hundreds of C programs in my ~/devel/ directory and sub-directories. is there a way i can use grep -r followed by some zsh, sh, bash, to find some code that starts with "&foo" or something similar? thanks in advance! (9 Replies)
Discussion started by: Gary Kline
9 Replies

3. UNIX for Dummies Questions & Answers

GREP Find & Replace <p class>

I am making an eBook. I am editing the html in BBedit. I need to replace all <p class="s5"> with just a <p>. How do I write this for GREP? Thank you, Abby (5 Replies)
Discussion started by: cuddlykitty
5 Replies

4. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

5. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

6. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

7. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

8. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

9. UNIX for Dummies Questions & Answers

help with find & grep commands

Folks; First about find: when i run this: find . -name '*log*' -mtime +10 -print | sed 's+^\./++;s+/.*++' | sort -u i got list of log files but also get a directories (although directory names doesn't have "log" in it). How can i exclude the directory from the output of this find command? ... (2 Replies)
Discussion started by: moe2266
2 Replies
Login or Register to Ask a Question