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

Stuart Johnston sjohnston at vaultranet.com
Fri Nov 7 11:16:36 CST 2003


Thanks to everyone for their suggestions.  grep -L and/or xargs were the 
pieces I was missing - I'll have to remember them for later.  Rusty's 
solution seemed to work the best, at first glance, but my problem turned 
out to be more complicated than I thought.

What I really need is to find all html input tags whose maxlength fields 
don't match up with the corresponding database column.  Extra Credit 
anyone?  :)

thanks again,
Stuart Johnston


Rusty Haddock wrote:
> 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-





More information about the Discuss mailing list