I've used perl to do this, as you can use perl to build a regex from an array:
#!/usr/bin/perl
use strict;
use warnings;
open ( my $searchfile, '<', "searchfile.txt" ) or die $!;
my @search_for = <$searchfile>;
close ( $searchfile );
my $search_regex = join ( "|", map {quotemeta} @search_for );
$search_regex = qr/$search_regex/;
print "Regex: $search_regex\n";
foreach my $file ( glob ( "somefolder/*.txt" ) ) {
open ( my $check, '<', $file ) or die $!;
while ( <$check> ) {
print if m/$search_regex/;
}
close ( $check );
}
Note - quotemeta
will escape metacharacters, which is good if you want to search for things including backslashes, spaces etc. But bad if you want to specify regex patterns.