Find,display files which do NOT contain...

Eclipse Eclipse ecl-sc1
April 20, 2010 at 08:37:12
Specs: Linux/Ubuntu
Friends,
I 5 given paths or directory.
I need to go to each path and path search all the files.
The files which do NOT contain two particular strings/words "XXXX" and "YYYY" need to be printed in the output.
I need to print only the filenames (not the path ) which do not contain the strings.
I am confused how to use find or exec and fgrep in combination.
Could anyone please help me writing a oneliner or two liner to achieve this?

I tried to use the below.
find . -type f -exec fgrep "Rani" {} \; -print
This displayed all the lines containing the word followed by the file name.
But i want only filenames which dnt contain the strings.

Any thought would be helpful!!


See More: Find,display files which do NOT contain...

Report •


#1
April 20, 2010 at 14:31:21
i couldn't even get yours to run.
"missing argument to -exec"
I tried lots of variations till i got mad and quit.
I would use expletives if the forum permitted it!
tried it on ubuntu Linux on my isp shell account (telnet).
what's the magic word to make find -exec work?

Report •

#2
April 20, 2010 at 17:30:21
Friend,
Here goes my UBUNTU 8.10 o/p.
Geeking4awhile@Geeking4awhile:~/scripts$ find . -type f -exec fgrep "Rani" {} \; -print
Rani my sister never uses Linux
./demofile1.sh

Rani does not know the power of UNIX.
./newfile

I also got the same on putty which connects to SOLARIS from windows.



Report •

#3
April 20, 2010 at 18:57:11
i have no clue what i was doing wrong, honestly - i thought i copied your code identically, but apparently not, since now it works. in fact, when it took "-print" off and add -L, it worked the way you want it to:
find . -type f -exec fgrep -L "testing" {} \;
(note the L has to be capitalized for string-exclusion. small L reports string-inclusion files.)
ps: managed to get rid of the path, too:
find . -type f -exec fgrep -L -q "testing {} \; -printf %f"\n"
i learn something everyday in this place!

Report •

Related Solutions

#4
April 20, 2010 at 21:03:33
You are good in this Man.Thanks!
Just was experimenting with the options you provided.
Some peculiar things did i notice.
Have a look below.
Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L "Rani" {} \;
./testArgument.sh
./test/caps_name
./test/sorted_names
./test/sname
./test/new_sorted_names
./demofile2.sh
./elf.sh
./ChessBoard.sh
./sumNo.sh
./testQuery
./rmDemo.sh
./biggestNo.sh
Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L "Rani" {} \; | wc -l
12
Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L "Rani" {} \; -print | wc -l
13
Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L -q "Rani" {} \; -print | wc -l
1
Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L -q "Rani" {} \; -print
./demofile1.sh
Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L "Rani" {} \; -printf %f
./testArgument.sh
./test/caps_name
./test/sorted_names
./test/sname
./test/new_sorted_names
./demofile2.sh
./elf.sh
./ChessBoard.sh
./sumNo.sh
./testQuery
./rmDemo.sh
./biggestNo.sh
demofile1.shGeeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec fgrep -L "Rani" {} \; -printf %f "\n"
find: paths must precede expression: \n
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Geeking4awhile@Geeking4awhile:~/scripts# -printf %f"\n"-printf %f"\n

So not retty sure what is going wrong with this printf option.

And one more thing

as my requirement is for two strings i used the below

Geeking4awhile@Geeking4awhile:~/scripts# find . -type f -exec egrep '(Vivek|Rani)' {} \; -print
Rani my sister never uses Linux
Vivek care for.
./demofile1.sh

this is to search all files with "Vivek" or "Rani" strings(for eg.)


Report •

#5
April 21, 2010 at 13:20:42
here's what worked on mine:
first, just using grep:
egrep -L "test|file" *
but that doesn't do subdirectories. harking back to the original specs, this worked:
find . -type f -exec egrep -L -q "test|file" {} \; -printf %f"\n"
the -q on egrep suppresses output of egrep so it doesn't get doubled (since the output has the pathstring on it, we don't want it). the -printf %f generates the bare filename but without newlines, so the "\n" is required to add those.
and using egrep lets us look for two strings sep by |, as you know.
worked on ubuntu version 8.04.2

Report •


Ask Question