I wrote the following code, where:
$1= Input .csv file$2= list of strings to be searched in$1$3= list of different strings to be searched in$2
while read str1
do
while read str2
do
grep $str1 $1 | grep $str2 | cut -d "," -f 6 > ${str1}_${str2}.txt
done < $3
done < $2
It basically does what I want it to do (search for two different strings from separate input files, extract field 6 of lines that contain both strings and write the content of field 6 into a result file). However, of course, result files are created for all possible combinations of strings from $2 and $3, even if they are empty. Is there a way to prevent the creation of empty files in general or do I have to remove them at the end?
greps per line over could be modified to a single-passjoinpiped to a loop (inawk, if we cared about performance) that splits results out into separate files. But details matter, and they aren't adequately given here.