[Techtalk] real life kewl text-processing and regexps samples wanted

Brenda Bell k15a-list-linuxchix at theotherbell.com
Fri Jan 9 23:30:12 EST 2004


Quoting Elena Bevell <elena.bevell at myrealbox.com>:

> I like this recursive grep that I found somewhere:
> 
> find  . -type f -exec grep "thing-to-find" {} \;
> 
> note that there is no space between the two braces
> and no space between the backslash and the semicolon,
> but there is a space between the second brace and the backslash.
> 
> Can someone explain the spaces and why this works?

Assume the find command lists two files: filea and fileb.  The -exec will
execute grep once for each file.  If you were to do this manually, you'd
have to type:

    grep "thing-to-find" filea
    grep "thing-to-find" fileb

Since spaces must appear in the exec command argument exactly as they would
appear if you executed the command manually, you must have a space before
the {} which is where the file name gets inserted.

The -exec argument consists of everything up to a ; argument.  Since
arguments are delimited by spaces, you must have a space before the ;. 
Iow, you can put additional find arguments after the ; as in:

    find  . -type f -exec grep "thing-to-find" {} ; -print

It's been a while, but I'm pretty sure this is correct.

-- 
Brenda
http://opensource.theotherbell.com



More information about the Techtalk mailing list