On 06/26/2014 12:40 PM, Greg Freemyer wrote:
All,
I know "grep -F -f pattern_file <files-to-search>
will give me a list of all lines with a pattern in them.
I want to know which of the patterns had no matches.
I tried "grep -F --count -f pattern_file <files-to-search>" but it gives a cumulative count for all patterns
I want a count per pattern so I can find the patterns with 0 count.
Do I have to write a bash loop and call grep once for each pattern?
It depends. You could try two variants. The first is "-v". What's not there. The second is look at the return/exit code for a FAILure to find any of the patterns. It depends on a few details about the search you haven't mentioned. Such as "many matches except for one' vs "none of the patterns". The other thing you can do is not use grep. My first thought is to use awk, but sometimes that has awk-ward sytax. My second though is that this is an excellent example for perl to show of, but that is predicted on you being familiar enough with perl. I was once but not now. http://www.theunixschool.com/2012/09/grep-vs-awk-examples-for-pattern-search... This is interesting but a bit lame in places. http://www.unix.com/shell-programming-and-scripting/183001-multiple-pattern-... It doesn't mention that you hashed indexed arrays to keep a count of which strings get matched. This looks close http://unix.stackexchange.com/questions/50491/the-simplest-method-to-count-l... -- /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org