Operating System - HP-UX
1855431 Members
12591 Online
104111 Solutions
New Discussion

HPUX 10.20 / 11.00 Search

 
SOLVED
Go to solution
Mark Treen_1
Advisor

HPUX 10.20 / 11.00 Search

This may be a little simple but it has stumped me!! Does anybody know a command and syntax where I can search every file on the server for a word!!!!

e.g. I need to see which files contain the word 'test'

Please help :-)
Mark Treen
10 REPLIES 10
Stefan Farrelly
Honored Contributor

Re: HPUX 10.20 / 11.00 Search

You will have to be careful only to search text files as if you search binary files (executables or databases/indexes) you will pick up control characters which will completely screw up your display/window.

This works for me;

find . -type f -print -exec grep -i "" {} \;

Send the output to a file and when done edit it and search for your string as this lists every single file as it searches it and only if it finds your string do you want to lookup the preceeding line which is the name of the file containing it.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Bill McNAMARA_1
Honored Contributor

Re: HPUX 10.20 / 11.00 Search

quick and dirty:
find . -type f | xargs grep test



It works for me (tm)
Mark Treen_1
Advisor

Re: HPUX 10.20 / 11.00 Search

Guys

Many thanks for the help! Can I just clarify the comment by Stefan - I do only want to see the files and paths that contain the string and not each file it searches.... should I stil use same criteria then??
Mark Treen
Vicente Sanchez_3
Respected Contributor
Solution

Re: HPUX 10.20 / 11.00 Search

Hi,

Try this:

for i in $(find / -type f)
do
tipo_fich=$(file $i|grep "text")
if [ $? -eq 0 ];then
echo "FILE: $i">>/tmp/fich.out
grep -n "test" $i>>/tmp/fich.out
fi
done

HTH, Vicente.
Ian Box
Advisor

Re: HPUX 10.20 / 11.00 Search

How about:

find / -type f | grep -l test {} \;

The grep option -l only lists the filename if the file contains the requested text.
Mehdi_1
Regular Advisor

Re: HPUX 10.20 / 11.00 Search

Hi

This what I normaly use myself:

find . -name '*' -exec grep -l 'Your test word' {} \;

Also there is a program called findgrep, it is using perl and it very handy. you can downlaoed the depot and install on your system, it is good program to have.

http://hpux.connect.org.uk/hppd/hpux/Misc/findgrep-1.0

cheers

Mehdi
Ian Box
Advisor

Re: HPUX 10.20 / 11.00 Search

Oops, that should have been:

find / -type f -exec grep -l test {} \;
Stefan Farrelly
Honored Contributor

Re: HPUX 10.20 / 11.00 Search

Yeah, just add in the -l option to grep and remove the -print;

find . -type f -exec grep -li "" {} \;
Im from Palmerston North, New Zealand, but somehow ended up in London...
H.Merijn Brand (procura
Honored Contributor

Re: HPUX 10.20 / 11.00 Search

 
Enjoy, Have FUN! H.Merijn
Ramkumar Devanathan
Honored Contributor

Re: HPUX 10.20 / 11.00 Search

Hi,

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x8d9619434a69d711abdc0090277a778c,00.html

I know I am late, but a similar query was asked just yesterday - link above.

- ramd.
HPE Software Rocks!