Hi folks,
I have two files, FILE1 and FILE2. Each of the two files is an array of
numbers. I want to check for the occurrence of each element of FILE1 in
FILE2. In other words, FILE2 is checked for the occurrence of each of the
elements in of FILE1.
For any element of FILE1 that occurs in FILE2, this element is saved in a
file, FILE3.txt.
I tried the attached Perl script to perform this exercise but the script
failed with the following error message:
"main:database" used only once: possible typo at ./GREP1.pl line 8"
Kindly assist me with a solution to actualising this task.
Regards,
Ken
<<GREP1.pl.txt>>
#!/usr/bin/perl -w
open FILE1, "</tmp/AAA.txt" or die "Can,t open AAA.txt: $!";
open FILE2, "</tmp/DATA.dat" or die "Can't open DATA.dat: $!";
open OUT, ">>/tmp/FILE3.txt" or die "Can't open BBB.txt: $!";
@numbers = <FILE1>;
@database = <FILE2>;
close(FILE1);
foreach $number (@numbers) {
chomp($number);
print OUT grep $number, <FILE2>;
}
close(FILE2);
close(OUT);