File comparision
File comparision
(OP)
Hi,
I need to check the contents of two files line by line.
For example:
File1 contains the following
Jim@tek.com
Tom@tek.com
Tim@tek.com
File2 contains:
Sam@tek.com
oprah@tek.com
Tim@tek.com
Tom@tek.com
I need to compare first File1 with File2 and find if there is any thing in File1 that is not in File2.
In this example, we've Jim@tek.com which is not in File2.
Then Jim@tek.com needs to be written to a DELETE file.
The, i need to compare File2 with File1 to see if there's anything in File2 not found in FIle1.
In this example, we've Sam@tek.com & oprah@tek.com.
Both these entries should be writtento another file called ADD.
Is there a way to accomplish this in Perl?
Thanks for any help.
I need to check the contents of two files line by line.
For example:
File1 contains the following
Jim@tek.com
Tom@tek.com
Tim@tek.com
File2 contains:
Sam@tek.com
oprah@tek.com
Tim@tek.com
Tom@tek.com
I need to compare first File1 with File2 and find if there is any thing in File1 that is not in File2.
In this example, we've Jim@tek.com which is not in File2.
Then Jim@tek.com needs to be written to a DELETE file.
The, i need to compare File2 with File1 to see if there's anything in File2 not found in FIle1.
In this example, we've Sam@tek.com & oprah@tek.com.
Both these entries should be writtento another file called ADD.
Is there a way to accomplish this in Perl?
Thanks for any help.
RE: File comparision
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
RE: File comparision
RE: File comparision
# read file 2 into an hash array
open(F,"file2") || die;
while(<f>){
chomp;
$file_two{$_)=1;
}
close f;
# now work through file1 searching through
# file2's hash array and printing out lines
# from file1 not in file2
open(F,"file1") || die;
while(<f>){
chomp;
unless ($file_two($_)) {
print "$_\n";
}
}
close f;
exit 0;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
RE: File comparision
It works!.
Thanks,
RE: File comparision
(actually, technically speaking -- that's a lie)
Glad you're sorted -- and we'll see you back here I hope?
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.