Re: Grep Guru

2008-06-11 Thread Ian Smith
On Mon, 9 Jun 2008, Giorgos Keramidas wrote:
  On Tue, 10 Jun 2008 01:44:36 +1000 (EST), Ian Smith [EMAIL PROTECTED] 
  wrote:
  On Sun, 8 Jun 2008 16:07:12 -0700 Bill Campbell [EMAIL PROTECTED] wrote:
  On Mon, Jun 09, 2008, Raphael Becker wrote:
  On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
   find . -type f -print0|xargs -0 grep grepoptions text to search
  
   There's no more need for find | xargs
  
   Try:
  
   find . -type -f -exec grep grepoptions text to search {} \+
  
   -exec foo {} \+ behaves like xargs foo
   -exec foo {} \; exec foo for every file
  
   Thanks for this kick; I'd missed or misunderstood using {} \+
  
   The issue here is that grep execs grep for each file found while
   xargs batches the files.
  
   If find(1) is to be believed, so does -exec utility [argument ...] {} +
  
  Yes, sure.  I think Bill was just being extra-conservative[1] and he
  explicitly chose to quote `+' with a backslash to avoid spurious
  interpreration by the shell.  I also type `\+' out of habbit most
  of the time.

It doesn't hurt.  My tests used \+ too, though after seeing yours I
tried with just '+' which works in tcsh anyway, unlike unescaped ';'

(It was Raphael actually, though I was replying to Bill's)

  [1] BSD users tend to be this way, but that's a good thing, right? :)

Right!  Of course for balance we have a 'left!' of out-there developers,
forever pushing envelopes, generating need for updates .. but we'd best
leave the stability vs progress politics to its playground on stable@ :) 

cheers, Ian

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-09 Thread Giorgos Keramidas
On Sun, 8 Jun 2008 16:07:12 -0700, Bill Campbell [EMAIL PROTECTED] wrote:
 On Mon, Jun 09, 2008, Raphael Becker wrote:
On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
 find . -type f -print0|xargs -0 grep grepoptions text to search

There's no more need for find | xargs

Try:

find . -type -f -exec grep grepoptions text to search {} \+

-exec foo {} \+ behaves like xargs foo
-exec foo {} \; exec foo for every file

 The issue here is that grep execs grep for each file found while
 xargs batches the files.

The \+ trick behaves like xargs, so this shouldn't be an issue :)

 This is of particular importance if one wants to see the file
 names in the output.

You can ensure the same even if xargs picks up a single file to grep
with

xargs -0 grep pattern /dev/null

This will cost an open() / read() pair for each batch of files, but it
ensures that grep will always see at least two file names, and it should
print the filename of any matching files.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-09 Thread Giorgos Keramidas
On Sun, 08 Jun 2008 22:23:19 +0200, Simon Jolle sjolle [EMAIL PROTECTED] 
wrote:
 On 06/08/2008 10:12 PM, Bill Campbell wrote:
 On Sun, Jun 08, 2008, Jos Chrispijn wrote:
 I tried to make a grep script on find a string in all files on path
 ./ and down. It does anything exept searching in files and reporting
 them.  Is there a Grep Guru who can hint me out? Thanks,

 I expect you need something like:

 find . -type f -print0 | xargs -0 grep pattern

 Or install the GNU grep (from the man)

 -R, -r, --recursive
 Read all  files  under  each  directory,  recursively;  this  is
 equivalent to the -d recurse option.

/usr/bin/grep *is* GNU grep in FreeBSD:

% [EMAIL PROTECTED]:/home/keramida$ grep --version
% grep (GNU grep) 2.5.1-FreeBSD
%
% Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
% This is free software; see the source for copying conditions. There is NO
% warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%
% [EMAIL PROTECTED]:/home/keramida$

AFAIK, Gabor Kovesdan is working on replacing grep(1) with a
BSD-licensed implementation, but he also tries to keep UI
compatibility as much as possible.  So I guess the -r/-R option
should work in that version too once it hits the tree.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-09 Thread Ian Smith
On Sun, 8 Jun 2008 16:07:12 -0700 Bill Campbell [EMAIL PROTECTED] wrote:
  On Mon, Jun 09, 2008, Raphael Becker wrote:
  On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
   find . -type f -print0|xargs -0 grep grepoptions text to search
  
  There's no more need for find | xargs
  
  Try: 
  
  find . -type -f -exec grep grepoptions text to search {} \+
  
  -exec foo {} \+ behaves like xargs foo  
  -exec foo {} \; exec foo for every file

Thanks for this kick; I'd missed or misunderstood using {} \+

  The issue here is that grep execs grep for each file found while
  xargs batches the files.

If find(1) is to be believed, so does -exec utility [argument ...] {} +

  This is of particular importance if one wants to see the file
  names in the output.  In relation to this, if one wants to be
  sure that grep always generates the file name, insure that it
  always gets at least two files as arguments:
  
  find . -type f -print0 | xargs -0 grep pattern /dev/null

Another good clue.  Many ways to do anything; I've often used such as:

% find /sys/ -name *.[chm] -exec egrep -Hi 'CPUFREQ_[GS]ET' {} \;

which has grep print the filenames, rather than using -print with find,
but I've just now run the above find, then using \+ instead, twice each,
and am pleased to learn that the latter method runs ~4 times faster in
real time and is even lighter on the system:

% time find /sys/ -name *.[chm] -exec grep -Hi 'CPUFREQ_[GS]ET' {} \;
/sys/kern/kern_cpu.c:static int cpufreq_settings_sysctl(SYSCTL_HANDLER_ARGS);
  [.. etc ..]
20.524u 46.205s 4:03.91 27.3%   79+201k 5698+0io 0pf+0w

% time find /sys/ -name *.[chm] -exec grep -Hi 'CPUFREQ_[GS]ET' {} \+
1.756u 3.058s 1:07.51 7.1%  81+290k 7148+0io 13pf+0w

% time find /sys/ -name *.[chm] -exec grep -Hi 'CPUFREQ_[GS]ET' {} \;
21.742u 44.382s 3:57.99 27.7%   79+200k 7144+0io 0pf+0w

% time find /sys/ -name *.[chm] -exec grep -Hi 'CPUFREQ_[GS]ET' {} \+
1.651u 3.134s 0:58.39 8.1%  75+267k 7149+0io 10pf+0w

(Ignore sloth; poor 300MHz Celeron already busy dumping /usr over nfs :)

  FWIW, I have learned about gnu-grep's -r option reading this
  thread, which I had not noticed previously.  I guess that just
  goes to show that old habits die hard :-).

When you're on a good thing :) but always plenty new tricks to learn.

cheers, Ian

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-09 Thread Giorgos Keramidas
On Tue, 10 Jun 2008 01:44:36 +1000 (EST), Ian Smith [EMAIL PROTECTED] wrote:
On Sun, 8 Jun 2008 16:07:12 -0700 Bill Campbell [EMAIL PROTECTED] wrote:
On Mon, Jun 09, 2008, Raphael Becker wrote:
On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
 find . -type f -print0|xargs -0 grep grepoptions text to search

 There's no more need for find | xargs

 Try:

 find . -type -f -exec grep grepoptions text to search {} \+

 -exec foo {} \+ behaves like xargs foo
 -exec foo {} \; exec foo for every file

 Thanks for this kick; I'd missed or misunderstood using {} \+

 The issue here is that grep execs grep for each file found while
 xargs batches the files.

 If find(1) is to be believed, so does -exec utility [argument ...] {} +

Yes, sure.  I think Bill was just being extra-conservative[1] and he
explicitly chose to quote `+' with a backslash to avoid spurious
interpreration by the shell.  I also type `\+' out of habbit most
of the time.

[1] BSD users tend to be this way, but that's a good thing, right? :)

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Bill Campbell
On Sun, Jun 08, 2008, Jos Chrispijn wrote:
I tried to make a grep script on find a string in all files on path ./ 
and down. It does anything exept searching in files and reporting them.
Is there a Grep Guru who can hint me out? Thanks,

I expect you need something like:

find . -type f -print0 | xargs -0 grep pattern

Bill
-- 
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:  (206) 236-1676  Mercer Island, WA 98040-0820
Fax:(206) 232-9186

We maintain that the very foundation of our way of life is what we call
free enterprise, said Cash McCall, but when one of our citizens
show enough free enterprise to pile up a little of that profit, we do
our best to make him feel that he ought to be ashamed of himself.
-- Cameron Hawley
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Wojciech Puchar
I tried to make a grep script on find a string in all files on path ./ and 
down. It does anything exept searching in files and reporting them.

Is there a Grep Guru who can hint me out? Thanks,


find . -type f -print0|xargs -0 grep grepoptions text to search

anyway it's nothing about being Grep Guru, or Find Guru

but it's really worth to be Man Guru :)

man find
man xargs

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Simon Jolle sjolle
On 06/08/2008 10:12 PM, Bill Campbell wrote:
 On Sun, Jun 08, 2008, Jos Chrispijn wrote:
 I tried to make a grep script on find a string in all files on path ./ 
 and down. It does anything exept searching in files and reporting them.
 Is there a Grep Guru who can hint me out? Thanks,
 
 I expect you need something like:
 
 find . -type f -print0 | xargs -0 grep pattern

Or install the GNU grep (from the man)

-R, -r, --recursive
Read all  files  under  each  directory,  recursively;  this  is
equivalent to the -d recurse option.

 Bill

cheers
Simon




signature.asc
Description: OpenPGP digital signature


Re: Grep Guru

2008-06-08 Thread Matthew Seaman

Simon Jolle sjolle wrote:

On 06/08/2008 10:12 PM, Bill Campbell wrote:

On Sun, Jun 08, 2008, Jos Chrispijn wrote:
I tried to make a grep script on find a string in all files on path ./ 
and down. It does anything exept searching in files and reporting them.

Is there a Grep Guru who can hint me out? Thanks,

I expect you need something like:

find . -type f -print0 | xargs -0 grep pattern


Or install the GNU grep (from the man)

-R, -r, --recursive
Read all  files  under  each  directory,  recursively;  this  is
equivalent to the -d recurse option.


The system supplied grep(1) /is/ gnu grep:

happy-idiot-talk:~:% grep --version 
grep (GNU grep) 2.5.1-FreeBSD


Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

grep -r works just fine.

Cheers,

Matthew

--
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
 Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
 Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature


Re: Grep Guru

2008-06-08 Thread Paul Procacci

Jos Chrispijn wrote:
I tried to make a grep script on find a string in all files on path ./ 
and down. It does anything exept searching in files and reporting them.

Is there a Grep Guru who can hint me out? Thanks,

-- Jos
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
[EMAIL PROTECTED]

You want it to report the files in which the string was found?

grep -rl pattern path

~Paul
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Frank Shute
On Sun, Jun 08, 2008 at 10:23:19PM +0200, Simon Jolle sjolle wrote:

 On 06/08/2008 10:12 PM, Bill Campbell wrote:
  On Sun, Jun 08, 2008, Jos Chrispijn wrote:
  I tried to make a grep script on find a string in all files on path ./ 
  and down. It does anything exept searching in files and reporting them.
  Is there a Grep Guru who can hint me out? Thanks,
  
  I expect you need something like:
  
  find . -type f -print0 | xargs -0 grep pattern
 
 Or install the GNU grep (from the man)
 
 -R, -r, --recursive
 Read all  files  under  each  directory,  recursively;  this  is
 equivalent to the -d recurse option.
 

What's gained from GNU grep? FreeBSD grep, automatically recurses in
to each subdir unless given the -maxdepth option.

Looks like FreeBSD grep wins (one less argument needed) ;)

  Bill
 
 cheers
 Simon
 
 

Regards,

-- 

 Frank 


 Contact info: http://www.shute.org.uk/misc/contact.html 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Paul Schmehl
--On June 8, 2008 1:12:56 PM -0700 Bill Campbell [EMAIL PROTECTED] 
wrote:



On Sun, Jun 08, 2008, Jos Chrispijn wrote:

I tried to make a grep script on find a string in all files on path ./
and down. It does anything exept searching in files and reporting them.
Is there a Grep Guru who can hint me out? Thanks,


I expect you need something like:

find . -type f -print0 | xargs -0 grep pattern



Or just grep -r string path

Paul Schmehl
If it isn't already obvious,
my opinions are my own and not
those of my employer.


Re: Grep Guru

2008-06-08 Thread Frank Shute
On Sun, Jun 08, 2008 at 09:34:20PM +0100, Frank Shute wrote:

 On Sun, Jun 08, 2008 at 10:23:19PM +0200, Simon Jolle sjolle wrote:
 
  On 06/08/2008 10:12 PM, Bill Campbell wrote:
   On Sun, Jun 08, 2008, Jos Chrispijn wrote:
   I tried to make a grep script on find a string in all files on path ./ 
   and down. It does anything exept searching in files and reporting them.
   Is there a Grep Guru who can hint me out? Thanks,
   
   I expect you need something like:
   
   find . -type f -print0 | xargs -0 grep pattern
  
  Or install the GNU grep (from the man)
  
  -R, -r, --recursive
  Read all  files  under  each  directory,  recursively;  this  is
  equivalent to the -d recurse option.
  
 
 What's gained from GNU grep? FreeBSD grep, automatically recurses in
 to each subdir unless given the -maxdepth option.
 
 Looks like FreeBSD grep wins (one less argument needed) ;)

Sorry, got confused between grep and xargs!

 
 Regards,
 
 -- 
 
  Frank 
 

-- 

 Frank 


 Contact info: http://www.shute.org.uk/misc/contact.html 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Simon Jolle sjolle
On 06/08/2008 10:26 PM, Matthew Seaman wrote:
 The system supplied grep(1) /is/ gnu grep:
 
 happy-idiot-talk:~:% grep --version grep (GNU grep) 2.5.1-FreeBSD

[...]

Sorry you are right. I didn't had any FreeBSD box around.

 Cheers,
 Matthew

cheers
Simon




signature.asc
Description: OpenPGP digital signature


Re: Grep Guru

2008-06-08 Thread Raphael Becker
On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
 find . -type f -print0|xargs -0 grep grepoptions text to search

There's no more need for find | xargs

Try: 

find . -type -f -exec grep grepoptions text to search {} \+

-exec foo {} \+ behaves like xargs foo  
-exec foo {} \; exec foo for every file

Regards
Raphael

-- 
Raphael Becker  [EMAIL PROTECTED]  http://rabe.uugrn.org/
GnuPG:E7B2 1D66 3AF2 EDC7 9828  6D7A 9CDA 3E7B 10CA 9F2D
.|.|.|.|.|.|.|..


pgpNOAj47TfSE.pgp
Description: PGP signature


Re: Grep Guru

2008-06-08 Thread Bill Campbell
On Mon, Jun 09, 2008, Raphael Becker wrote:
On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote:
 find . -type f -print0|xargs -0 grep grepoptions text to search

There's no more need for find | xargs

Try: 

find . -type -f -exec grep grepoptions text to search {} \+

-exec foo {} \+ behaves like xargs foo  
-exec foo {} \; exec foo for every file

The issue here is that grep execs grep for each file found while
xargs batches the files.

This is of particular importance if one wants to see the file
names in the output.  In relation to this, if one wants to be
sure that grep always generates the file name, insure that it
always gets at least two files as arguments:

find . -type f -print0 | xargs -0 grep pattern /dev/null

FWIW, I have learned about gnu-grep's -r option reading this
thread, which I had not noticed previously.  I guess that just
goes to show that old habits die hard :-).

Bill
-- 
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:  (206) 236-1676  Mercer Island, WA 98040-0820
Fax:(206) 232-9186

Good luck to all you optimists out there who think Microsoft can deliver
35 million lines of quality code on which you can operate your business.
   -- John C. Dvorak
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Grep Guru

2008-06-08 Thread Jeffrey Goldberg

On Jun 8, 2008, at 5:50 PM, Raphael Becker wrote:


find . -type -f -exec grep grepoptions text to search {} \+

-exec foo {} \+ behaves like xargs foo
-exec foo {} \; exec foo for every file


Way cool!  I hadn't known that about find(1).

Cheers,

-j
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]