[NTLUG:Discuss] Find Files NOT containting 'string'

Rusty Haddock rusty at fe2o3.lonestar.org
Thu Nov 6 22:32:10 CST 2003


Overcome by acute stupidity,
Rusty Haddock managed to scribble something like:

    >Stuart Johnston wrote:
    >    >I need to search for files that contain one string but not another.  Can 
    >    >anyone suggest a linux command to do this?
    >
    >grep -l 'iwantthisstring' {list of files} | xargs grep -l -v 'idontwantthis'

Ooppsss, not quite.  Forgot to check my answer THOROUGHLY before
handing in the homework.  :-(   The answer is more like this:

grep -l 'iwantthisstring' {list of files} | xargs grep -L 'idontwantthis'

    >The first grep finds all the files with 'iwantthisstring'.
    >The list of files from this grep is fed into xargs which
    >runs grep -v on those files listing the ones that do NOT
    >have the string 'idontwantthis'.

Naturally, I thought -l -v would have given me the list of files that
did NOT contain the pattern.  Nyet!  Not so.  It really produces a list
of files that has lines that do NOT contain the pattern.  This probably
would have worked for the problem IFF each file had only one line.

    >As I've said a number of times before, 'xargs(1)' is your friend!  :-)

Still true though.

Sorry 'bout that.  Where's my wet noodle???

	-Rusty-
-- 
   _____        Rusty Haddock  =  KD4WLZ  =  rusty at fe2o3.lonestar.org
|\/   o \   o  **Out yonder in the Van Alstyne (TX) Metropolitan Area**
|   (  -<  O o              Microsoft is to software what
|/\__V__/                  McDonalds is to gourmet cooking



More information about the Discuss mailing list