RE: [Scottish] Best way to find text within files recursively?

2003-01-21 Thread Michael Cameron
>I'm not too hot on the -exec syntax for find (this may explain why I can
>never get that part to work and start piping things to xargs, perhaps
>unnecessarily!), I suspect it's the "\;" that I have problems with:
>what's that all about, or is it just "the rule" that you must finish
>your -exec "clause" with it?
>
Pretty much, you terminate the command with a semi colon but it (often) has
to be escaped (or quoted) so that the shell doesn't interpret it first.

The grep -r option is not available in all *nixes which is why I do not
favour it.

MC



___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



Re: [Scottish] Best way to find text within files recursively?

2003-01-20 Thread Graeme Mathieson
On Sun, Jan 19, 2003 at 11:32:20PM -, Michael Cameron wrote:
> 
> /dev/null is the second file

Doh.  I wondered why you'd bothered putting that in.
-- 
Right now, there are scr1pt k1dd13s plotting to DDoS my network, my co-lo
server is not responding  to pings and  the people that I IRC with may be
involved in both.  I'm  sysadmin Graeme Mathieson and this is the longest
day of my life.   http://www.wossname.org.uk/~mathie/

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



RE: [Scottish] Best way to find text within files recursively?

2003-01-19 Thread Paul Millar
On Sun, 19 Jan 2003, Michael Cameron wrote:
> > find . -type f -exec grep 'foo' {} /dev/null \;
> 
> > Also, since grep is only spawned with one filename, it will not
> >(iirc) issue the names of matching files in addition to the matching
> >line itself.  
> 
> /dev/null is the second file

Alternatively, one could use grep's -H option ;^)

Paul.


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Particle Physics (Theory & Experimental) GroupsDr Paul Millar 
Department of Physics and Astronomy [EMAIL PROTECTED]
University of Glasgow [EMAIL PROTECTED]
Glasgow, G12 8QQ, Scotland http://www.astro.gla.ac.uk/users/paulm 
+44 (0)141 330 4717A54C A9FC 6A77 1664 2E4E  90E3 FFD2 704B BF0F 03E9
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 


___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



RE: [Scottish] Best way to find text within files recursively?

2003-01-19 Thread Michael Cameron
> find . -type f -exec grep 'foo' {} /dev/null \;

> Also, since grep is only spawned with one filename, it will not
>(iirc) issue the names of matching files in addition to the matching
>line itself.  

/dev/null is the second file



___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



Re: [Scottish] Best way to find text within files recursively?

2003-01-19 Thread Graeme Mathieson
On Sun, Jan 19, 2003 at 11:19:08PM -, Michael Cameron wrote:
> >
> >find . -type f -print0 |xargs -0 grep 'foo'
> >
> I'd go for:
> 
> find . -type f -exec grep 'foo' {} /dev/null \;

See, that has two consequences.  grep is spawned once for every find
match (which, if you're running it on something slow and old is an
issue).  Also, since grep is only spawned with one filename, it will not
(iirc) issue the names of matching files in addition to the matching
line itself.  Of course, if that's a desired feature, you're sorted, but
in the original spec, I suspect it wasn't...
-- 
Right now, there are scr1pt k1dd13s plotting to DDoS my network, my co-lo
server is not responding  to pings and  the people that I IRC with may be
involved in both.  I'm  sysadmin Graeme Mathieson and this is the longest
day of my life.   http://www.wossname.org.uk/~mathie/

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



RE: [Scottish] Best way to find text within files recursively?

2003-01-19 Thread Michael Cameron
>
>find . -type f -print0 |xargs -0 grep 'foo'
>
I'd go for:

find . -type f -exec grep 'foo' {} /dev/null \;

or possibly:

find . -type f -exec grep -q  'foo' {} \; -print

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



Re: [Scottish] Best way to find text within files recursively?

2003-01-18 Thread Graeme Mathieson
On Sat, Jan 18, 2003 at 07:55:38PM +, Allan Whiteford wrote:
> 
> In a slightly more convoluted way, but one in which can be applied
> easily to any command to give recursive capabilities:
> 
> grep -l [EMAIL PROTECTED] `find .`
> 
> (Note the direction of the quotes, and also filenames with spaces will
> probably mess things up.)

It's also going to break grep if find returns too many results.  And
find there will return directories too, which grep will not take too
kindly to.  My SOP recursive grep is:

find . -type f -print0 |xargs -0 grep 'foo'

OTOH, I've no idea offhand why I don't just use rgrep (aka `grep -r`)...
:-)
-- 
Right now, there are scr1pt k1dd13s plotting to DDoS my network, my co-lo
server is not responding  to pings and  the people that I IRC with may be
involved in both.  I'm  sysadmin Graeme Mathieson and this is the longest
day of my life.   http://www.wossname.org.uk/~mathie/

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



Re: [Scottish] Best way to find text within files recursively?

2003-01-18 Thread Allan Whiteford
[EMAIL PROTECTED] wrote:
> 
> > for (every folder in this directory)
> >   grep -l [EMAIL PROTECTED] *
> 
> Would "grep -rl [EMAIL PROTECTED] *" do what you want?
> 
> Steven Murdoch.
> 
> ___
> Scottish mailing list
> [EMAIL PROTECTED]
> http://mailman.lug.org.uk/mailman/listinfo/scottish

In a slightly more convoluted way, but one in which can be applied
easily to any command to give recursive capabilities:

grep -l [EMAIL PROTECTED] `find .`

(Note the direction of the quotes, and also filenames with spaces will
probably mess things up.)

Thanks,

Allan
-- 
The average person's left hand does 56% of the typing.

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



Re: [Scottish] Best way to find text within files recursively?

2003-01-18 Thread iain d broadfoot
* [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
> > for (every folder in this directory)
> > grep -l [EMAIL PROTECTED] *
> 
> Would "grep -rl [EMAIL PROTECTED] *" do what you want?
> 

yep, it sure does. :D

i'd add -i and quotes around the email, just for added goodness..

iain

-- 
wh33, y1p33 3tc.

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish



Re: [Scottish] Best way to find text within files recursively?

2003-01-18 Thread scottish+Steven . Murdoch
> for (every folder in this directory)
>   grep -l [EMAIL PROTECTED] *

Would "grep -rl [EMAIL PROTECTED] *" do what you want?

Steven Murdoch.

___
Scottish mailing list
[EMAIL PROTECTED]
http://mailman.lug.org.uk/mailman/listinfo/scottish