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

David Camm dcamm at advwebsys.com
Thu Nov 6 20:10:23 CST 2003


well of course, stuart. grep needs a file or file list to operate on. my 
apologies for leaving out some of the syntax. i just responded with the critical 
stuff.

Stuart Johnston wrote:
> The first grep needs some input so I would say:
> 
> grep 'thestringiwant' * |grep -v 'thestringidontwant'
> 
> The first grep will output (send to the second) only the lines that 
> match the first string.  So, unless I misunderstand, this will only work 
> if both strings are on the same line.  That is not the case in my 
> situation.  Perhaps I should have made that more clear.
> 
> Thanks,
> Stuart Johnston
> 
> 
> David Camm wrote:
> 
>> 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
>>>
>>
>>
>>
>> _______________________________________________
>> https://ntlug.org/mailman/listinfo/discuss
>>
> 
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
> 





More information about the Discuss mailing list