Hello, I am a novice at Perl.
I have a SOURCE text file with a list of strings, such as
http://www.google.com
www3.manish.net
www.nov8rix.com
www.thisisannoying.com
and a 2nd text file FILTER TERMS with a list of terms such as
google
manish
www.thisisannoying.com
What I want to do is read the 2nd file and using the list of those terms, to filter out the first file.
The desired end result OUTPUT would be
www.nov8rix.com
It would not write
http://www.google.com --- because it matches the "google"
www3.manish.net --- because it matches the "manish"
www.thisisannoying.com --- because it matches the "www.thisisannoying.com"
Can anyone please help me figure out how to do this?
Here is the code I have thus far (this is the 20th iteration of various attempts, having spent about 5 hours on this already today --- see, I am new at this!)Thank you.#!/usr/bin/perl open (F1, "<filterTerms.txt"); open (F2, "<source.txt"); my %terms = (); my %source = (); while (<F1>) { my $term=$_; chomp ($term); $terms{$term}=$term; } while (<F2>) { my $item=$_; chomp ($item); $source{$item}=$item; foreach (keys %source) { if ($source=~m/($term{$term})/) { #do nothing } else { print $1."\n"; } } } close (F1); close (F2);
In reply to Filtering Source Text File with 2nd Text File of Terms by Loops303
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |