in reply to How can I grep these IP-addresses from these logfiles?
my @lines = qw/marge homer bart jerry maggie george elaine kramer lisaross chandler fibi joey monica rachel batman robin catwoman batgirl superman thetick hollywood studio universal compton harbor downtown monica venice oc oxnard ventura oaks/; my @kwords = qw/bart maggie monica pete/; my @matches = map { my $kword=$_; grep /\b$kword\b/, @lines } @kwords; { local $, = "\t"; print @matches; }
This is just an example. A little tinkering will match it to your needs. Enjoy!
Update: I tested the above method against the regexp method in the first followup in this thread. The regexp (alternation) method proved to be faster for this small test-set of data. Even when I grew the keyword list to about 40 words, and the array of strings to find keywords in to about 40 lines of 10 "words" each, I still found alternation to be faster. I don't know what to expect if the keyword list gets REALLY big. Obviously my method puts a loop inside a loop. But alternation itself isn't considered terribly fast. Someone with a lot of test data might be able to shed light.
Dave
|
|---|