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

David Camm dcamm at advwebsys.com
Thu Nov 6 19:16:56 CST 2003


grep 'thestringiwant'|grep -v 'thestringidontwant'

gives the files that have 'thestringiwant' and dont' have 'thestringidontwant'

and, btw, grep is not 'line-based' it checks every line in the file, but only 
reports the result for the entire file. if a file does not contain 
'thestringidontwant' anywhere then grep -v will get it right.

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?
> 
> The first part is easy with grep but since grep is line based it doesn't 
> work will for the second part since pretty much every file will have at 
> least one line that does not contain the string.
> 
> I guess one way would be to grep a list of files containing the second 
> string and compare it against the list of files that contain the first 
> but I can't think how to easily XOR the two lists of files.  I don't 
> want to ask you to 'do my homework' for me but if you can pull a command 
> of the top of your head, I would appreciate it.
> 
> thanks,
> Stuart Johnston
> 
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
> 





More information about the Discuss mailing list