1828657 Members
7679 Online
109983 Solutions
New Discussion

finding files

 
SOLVED
Go to solution
Roberto Gallis
Regular Advisor

finding files

Hi all,
I need on hp-ux 11 to find files that does not contain a particular word.
For example I need to find all files that the word "willy" is not present.
Anybody can help me?

Roberto
6 REPLIES 6
Andreas Voss
Honored Contributor

Re: finding files

Hi,

here you are:

find ! -name '*willy*' -print

Regards
James R. Ferguson
Acclaimed Contributor

Re: finding files

Roberto:

# grep -v willy *

This will operate on all files in the current directory displaying the filenames where "willy" does NOT exist.

...JRF...
Rodney Hills
Honored Contributor
Solution

Re: finding files

This method is good when you are searching a specific set of subdirectories

find /thedirectory -print | xargs grep -c "willy" | grep ":0$"

The "-c" option of grep returns number of lines that pattern exists. The second grep will display those filenames that don't have "willy".
There be dragons...
Joseph C. Denman
Honored Contributor

Re: finding files

if you are looking for file containing the word willy and not willy in the file name, try this:

Go to the dir you wish to search

find . -type f | while read line
do
if grep "willy" $line > /dev/null
then
echo $line
fi
done
If I had only read the instructions first??
Roberto Gallis
Regular Advisor

Re: finding files

Hi,

grep -v willy *
display the content of all files except the lines containing "willy"

Scripts of Joseph and Rodney do what I need.
Thank you all
Sincerly
Roberto
Roberto Gallis
Regular Advisor

Re: finding files

for Joseph:

I've added -v to the line
if grep "paperino" $line > /dev/null
and had what I need.
Thanks

Regards
Roberto