Assuming you just want to print the names of files containing ALL strings, here is a solution that will work for any number of strings and will do string comparisons, rather than regular expression comparisons:
gawk -v RS='\0' -v strings="string1 string2" ' BEGIN{ numStrings = split(strings,stringsA) } { matchCnt = 0 for (stringNr=1; stringNr<=numStrings; stringNr++) if ( index($0,stringsA[stringNr]) ) matchCnt++ } matchCnt == numStrings { print FILENAME } ' file*
Wait, I just noticed that you want to print files that DO NOT contain 2 lines. It will be:
gawk -v RS='\0' -v strings="string1 string2" ' BEGIN{ numStrings = split(strings,stringsA) } { matchCnt = 0 for (stringNr=1; stringNr<=numStrings; stringNr++) if ( index($0,stringsA[stringNr]) ) matchCnt++ } matchCnt == numStrings { matchesAll[FILENAME] } END { for (fileNr=1; fileNr < ARGC; fileNr++) { file = ARGV[fileNr] if (! (file in matchesAll) ) print file } } ' file*
To print the names of files that do not contain a single line, follow these steps:
gawk -v RS='\0' -v strings="string1 string2" ' BEGIN{ numStrings = split(strings,stringsA) } { for (stringNr=1; stringNr<=numStrings; stringNr++) if ( index($0,stringsA[stringNr]) ) matchesOne[FILENAME] } END { for (fileNr=1; fileNr < ARGC; fileNr++) { file = ARGV[fileNr] if (! (file in matchesOne) ) print file } } ' file*
source share