Operating System - HP-UX
1752604 Members
4442 Online
108788 Solutions
New Discussion юеВ

Re: Searching an IP Address in one of the file from the whole system

 
SOLVED
Go to solution
ESS IITC
Occasional Contributor

Searching an IP Address in one of the file from the whole system

Dear all,

I have to find out one IP Address which is configured in a file. This file I'm not aware & can be placed in any directory or sub-directory in the System
OS is HPUX 11iv1.
I could not find any option in "grep" with recursive search.

Please advise.
Thanks in advance.
Vimal Upreti
8 REPLIES 8
Dennis Handly
Acclaimed Contributor
Solution

Re: Searching an IP Address in one of the file from the whole system

>I could not find any option in "grep" with recursive search.

You can combine find(1) with grep(1):
find / -exec grep -e "string1" +

The "-exec ... +" allows you to search lots of files at one invocation.
kemo
Trusted Contributor

Re: Searching an IP Address in one of the file from the whole system

find / -type f -exec grep -e "string" {} \;
Jai Ganesh
Trusted Contributor

Re: Searching an IP Address in one of the file from the whole system

Hi,

You can use
find / -type f -exec grep "" {} \; -print

Jai.
http://itmms.wordpress.com/
James R. Ferguson
Acclaimed Contributor

Re: Searching an IP Address in one of the file from the whole system

HI:

Don't use the '\;' terminator for find's '-exec'. Doing so means that you spawn *one* process for *every* entity that 'find' passes along.

Instead use the "+" terminator which signals the collection and bundling of very large number of arguments into a list that is passed to one or more spawned processes.

For small numbers of arguments, you probably won't notice the impact. In the case you are using, you will not only waste time but seriously degrade your system performance if you use '\;' instead of '+'.

Dennis meant to write:

# find / -exec grep -e "string1" {} +

...and most certainly meant to only examine files (and not directories too) by writing:

# find / -type f -exec grep -e "string1" +

Regards!

...JRF..

James R. Ferguson
Acclaimed Contributor

Re: Searching an IP Address in one of the file from the whole system

HI:

Don't use the '\;' terminator for find's '-exec'. Doing so means that you spawn *one* process for *every* entity that 'find' passes along.

Instead use the "+" terminator which signals the collection and bundling of very large number of arguments into a list that is passed to one or more spawned processes.

For small numbers of arguments, you probably won't notice the impact. In the case you are using, you will not only waste time but seriously degrade your system performance if you use '\;' instead of '+'.

Dennis meant to write:

# find / -exec grep -e "string1" {} +

...and most certainly meant to only examine files (and not directories too) by writing:

# find / -type f -exec grep -e "string1" {} +

Regards!

...JRF..

ESS IITC
Occasional Contributor

Re: Searching an IP Address in one of the file from the whole system

Dear Dennis Handly, kemo, Jai Ganesh, James R. Ferguson

Thanks a lot for your quick solution. It worked:
# find / -exec grep -e "string1" {} +

Regards.
Vimal
Dennis Handly
Acclaimed Contributor

Re: Searching an IP Address in one of the file from the whole system

>Thanks a lot for your quick solution. It worked:

If you are happy with the answers you were given, please read the following about how to assign points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33

>JRF: Don't use the '\;' terminator for find's -exec.

Another problem with ";" and grep is the fact that grep won't tell you the name of the file, since there is only one. Perhaps that's why Jai added -print to the end.
James R. Ferguson
Acclaimed Contributor

Re: Searching an IP Address in one of the file from the whole system

Hi (again) Vimal:

> Dennis: Another problem with ";" and grep is the fact that grep won't tell you the name of the file, since there is only one. Perhaps that's why Jai added -print to the end.

That's a good point. It's probably clearer (if for whatever reason one uses the ';' terminator to process one argument at a time) to do:

# find / -type f -exec grep -e "string1" /dev/null {} \;

When 'grep' sees two file arguments it shows any matches with the file name for identification. Of course nothing will ever match the empty '/dev/null'.

Regards!

...JRF...