Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GLOBAL SEARCH 2

Status
Not open for further replies.

OraMs

Programmer
Feb 12, 2000
40
US

How can a do a global search for a string? I'm new to Unix. I've tried using GREP, from a root directory, as follows:

grep -i "mystring" /*


It did not work.

I have read through every chapter in my Unix manual on grep without any luck. Thanks in advance for your time.
 
I have no Unix machine here to try it, but may idea would be to use the find command and pipe the result to the grep command.
Perhaps there are some modifications or a small script necessary but it should work.

hnd
hasso55@yahoo.com

 
hi Ora,

That's actually a bit fiddly. You only want to search the text files on your system so you have to pipe the output of the find command through the 'file' command and pick out just the text files - and search those with grep.
Mike
michael.j.lacey@ntlworld.com
 
Hello,

Just cd to the directory under which you want to perform the global search for "mystring". Then issue the following command:

find . -exec grep -in "mystring" {} \; -print 2>/dev/null

Thanks,
RajaniKant,
 
OK. Xargs, what does that do then? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
If you execute [tt]find[/tt] without using [tt]xargs[/tt] but using the [tt]-exec[/tt] option with [tt]grep[/tt] you'll end up running [tt]grep[/tt] [red]once with each and every file[/red] on your system. But using it with [tt]xargs[/tt] that way it lets give many many file names to [tt]xargs[/tt] and that last command will build extremely long command lines to give it to only some invocations of [tt]grep[/tt].

I hope it works...
 
Thx Elgis.

-ml Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top