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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching for strings

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
0
0
PT
Hi,

I need to search for an IP appearing in all the files in the entire machine.

I am currently using the cmd:
#>find . -type f -exec grep "198.164.13.64" '{}' \;

The problem is the above cmd is returning a huge amt of output most of which begin with "grep: can't open ..."

I have tried few other cmd but none very reliable.. would appreciate someone posting an efficient command for the above ..

thnx in adv,
 
I suppose you can add "| grep -v can't\ open".
 
If you are using ksh or bash, you can redirect the error messages to /dev/null:

find . -type f -exec grep "198.164.13.64" '{}' 2> /dev/null \;

 
Are you running this as root? If not, you don't have permission to access all files, hence the error. This rather spoils your chances of searching for the IP in the 'entire machine' too.
 
Hi,

Thanks for the suggestions but am still stuck with the problem..

I am using KSH but not running the cmd as root. However, I desire to search only in those files which my user has privileges to modify.

I am executing the comand in the "/" directory to search the entire "machine". Is this correct ?

The find result is also obtaining lot of ping request, junk like:
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=198.164.13.64)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=TRS.US1)(CID=(PROGRAM=)(HOST=ithp11)(USER=bc01))))

How do I filter these too ? in any case, I tried redirecting the output to a temp file and when I searched this file, the few files which actually contain the IP above do not appear !:(

thnx
 
If you only want to search files that you can modify, aren't most or perhaps even all of those in your directory? If so, why search starting at "/"?

Find has enough options to do this (user, group and perms) but that would be complex and you are also wasting a lot of time searching in places where you can't go. It might be quicker and a whole lot easier to do individual finds in only the directories of interest.

Tony Lawrence
Linux/Unix/Mac OS X Resources
 
The user I have is almost as good as the root. I have various directories under / , each with a number of files..

Even If I execute the command under each dir, the resulting output still contains a lot of junk..

In any case, I still need a command to dig up what is required...

thnx
 
Have you tried:

find . -type f -exec grep "198.164.13.64" '{}' \; | grep -v 'DESCRIPTION' 2> /dev/null

The grep -v will remove any of the 'junk' you describe above and send error messages to /dev/null. Does this fulfill your need?
 
Unfortunately not.. I am still getting a lot of "junk" and many files with the IP are not appearing... :(
 
Have you tried grep -l to produce a list of filenames containing the search string (files have full paths)? This significantly reduces the amount of output and produces a list that can be 'plugged' into another command.

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top