FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 10-03-2008, 08:08 PM
Bowie Bailey
 
Default find

MHR wrote:
> On Fri, Oct 3, 2008 at 7:27 AM, Akemi Yagi <amyagi@gmail.com> wrote:
> > On Fri, Oct 3, 2008 at 7:24 AM, Akemi Yagi <amyagi@gmail.com> wrote:
> > > On Fri, Oct 3, 2008 at 6:54 AM, Bo Lynch
> > > <blynch@ameliaschools.com> wrote:
> > > >
> > > > I would recommend taking a look at grep. THere are many ways
> > > > you can use it.
> > >
> > > One such example is:
> > >
> > > find . -type f -exec grep -il !* {} ; -exec grep -i !* {} ;
> > > -exec echo ;
> > >
> > > alias it to, say, findword and run: findword <text>
> >
> > Sorry, I missed the "!" in the above paste:
> >
> > find . -type f -exec grep -il !* {} ; -exec grep -i !* {} ;
> > -exec echo ;
>
> I tend to do this:
>
> find . -type f -exec grep <pattern> /dev/null {} ;
>
> The "/dev/null" is because grep doesn't show the file name unless
> there are at least two provided, and this accomplishes what Akemi's
> command above does but in a single command. Of course, it still takes
> forever if the directory whence the search begins is /.

Or you can do it like this:

find . -type f -exec grep -H <pattern> {} ;

>From the man page:
-H, --with-filename
Print the filename for each match.

--
Bowie
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-03-2008, 11:07 PM
MHR
 
Default find

On Fri, Oct 3, 2008 at 1:08 PM, Bowie Bailey <Bowie_Bailey@buc.com> wrote:
>
> Or you can do it like this:
>
> find . -type f -exec grep -H <pattern> {} ;
>

Or this:

grep -rH <pattern> .

Wait, that's too short....

:-)

mhr
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-06-2008, 09:41 AM
Ralph Angenendt
 
Default find

Akemi Yagi wrote:
>> find . -type f -exec grep -il !* {} ; -exec grep -i !* {} ; -exec echo ;
>>
>> alias it to, say, findword and run: findword <text>
>
> Sorry, I missed the "!" in the above paste:
>
> find . -type f -exec grep -il !* {} ; -exec grep -i !* {} ; -exec echo ;

If you are using GNU grep (well, you are using CentOS),

grep -ri "foo" dir/to/search/in

seems much shorter to me.

Cheers,

Ralph
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-06-2008, 04:15 PM
MHR
 
Default find

On Mon, Oct 6, 2008 at 2:41 AM, Ralph Angenendt <ra+centos@br-online.de> wrote:
>
> If you are using GNU grep (well, you are using CentOS),
>
> grep -ri "foo" dir/to/search/in
>
> seems much shorter to me.
>

Without the -H you don't get the file names....

mhr
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-06-2008, 04:26 PM
Ralph Angenendt
 
Default find

MHR wrote:
> On Mon, Oct 6, 2008 at 2:41 AM, Ralph Angenendt <ra+centos@br-online.de> wrote:
> > If you are using GNU grep (well, you are using CentOS),
> >
> > grep -ri "foo" dir/to/search/in
> >
> > seems much shorter to me.
> >
>
> Without the -H you don't get the file names....

Hu?

| [angenenr@shutdown httpd]$grep -ri virtu conf* | grep -v "#"
| conf.d/ssl.conf:<VirtualHost _default_:443>
| conf.d/ssl.conf:</VirtualHost>
| [angenenr@shutdown httpd]$grep -rHi virtu conf* | grep -v "#"
| conf.d/ssl.conf:<VirtualHost _default_:443>
| conf.d/ssl.conf:</VirtualHost>

Cheers,

Ralph
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-06-2008, 04:33 PM
MHR
 
Default find

On Mon, Oct 6, 2008 at 9:26 AM, Ralph Angenendt <ra+centos@br-online.de> wrote:
>
> Hu?
>
> | [angenenr@shutdown httpd]$grep -ri virtu conf* | grep -v "#"
> | conf.d/ssl.conf:<VirtualHost _default_:443>
> | conf.d/ssl.conf:</VirtualHost>
> | [angenenr@shutdown httpd]$grep -rHi virtu conf* | grep -v "#"
> | conf.d/ssl.conf:<VirtualHost _default_:443>
> | conf.d/ssl.conf:</VirtualHost>
>

Doh! Of course - -r implies multiple files, so without -h you _will_ get them.

Homer moment.

mhr
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-07-2008, 11:09 PM
Jeremiah Heller
 
Default find

On 6 Oct 2008, at 09:33, MHR wrote:

On Mon, Oct 6, 2008 at 9:26 AM, Ralph Angenendt <ra+centos@br-online.de
> wrote:


Hu?

| [angenenr@shutdown httpd]$grep -ri virtu conf* | grep -v "#"
| conf.d/ssl.conf:<VirtualHost _default_:443>
| conf.d/ssl.conf:</VirtualHost>
| [angenenr@shutdown httpd]$grep -rHi virtu conf* | grep -v "#"
| conf.d/ssl.conf:<VirtualHost _default_:443>
| conf.d/ssl.conf:</VirtualHost>



Doh! Of course - -r implies multiple files, so without -h you
_will_ get them.


Shorter still=P

[jf@betty conf.d]$ grep -i virtu *
ssl.conf:## the main server and all SSL-enabled virtual hosts.
ssl.conf:## SSL Virtual Host Context
ssl.conf:<VirtualHost _default_:443>
ssl.conf:# General setup for the virtual host, inherited from global
configuration


Filenames show even if a grep of many files only returns one result
[jf@betty conf.d]$ grep -i "loadmodule ssl" *
ssl.conf:LoadModule ssl_module modules/mod_ssl.so

Jeremiah
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-08-2008, 08:26 AM
Ralph Angenendt
 
Default find

Jeremiah Heller wrote:
> On 6 Oct 2008, at 09:33, MHR wrote:
>
>> On Mon, Oct 6, 2008 at 9:26 AM, Ralph Angenendt <ra+centos@br-online.de
>>> | [angenenr@shutdown httpd]$grep -ri virtu conf* | grep -v "#"
>>> | conf.d/ssl.conf:<VirtualHost _default_:443>
>>> | conf.d/ssl.conf:</VirtualHost>
>>
>> Doh! Of course - -r implies multiple files, so without -h you _will_
>> get them.
>
> Shorter still=P
>
> [jf@betty conf.d]$ grep -i virtu *

That might be shorter, but doesn't recurse down a directory tree (as was
required by the original poster).

Ralph
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-10-2008, 01:43 AM
MHR
 
Default find

On Mon, Oct 6, 2008 at 2:41 AM, Ralph Angenendt <ra+centos@br-online.de> wrote:
> Akemi Yagi wrote:
>>
>> Sorry, I missed the "!" in the above paste:
>>
>> find . -type f -exec grep -il !* {} ; -exec grep -i !* {} ; -exec echo ;
>
> If you are using GNU grep (well, you are using CentOS),
>
> grep -ri "foo" dir/to/search/in
>
> seems much shorter to me.
>

This works unless you are looking to search a specific set of files by
name, not just whole directories.

I routinely use searches like this to locate patterns in build trees,
but I typically only want to look in header or c source files (or
sometimes just the Makefiles. In my case, the find...grep form works
better because there may not be any of the files I want in the
directory from which I begin the search, only those farther down.

Cheers.

mhr
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 04:30 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org