C
clearguy02
I have two files (C:\test1.txt and C:\test2.txt) to parse. The first
file has 4 fields and the second one has two fields, but both files
have the "user_id" as the first field.
Example:
c:\test1.txt
=================
jcarter john (e-mail address removed) mstella
mstella mary (e-mail address removed) bborders
msmith martin (e-mail address removed) mstella
bborders bob (e-mail address removed) rcasey
swatson sush (e-mail address removed) mstella
rcasey rick (e-mail address removed) rcasey
c:\test2.txt
======================
aaboss active
jcarter active
msmith non-active
ssullivan non-active
rcasey non-active
usmiths active
===============================================
Now I want to check if each id from the second file exists in the
first one or not. I want the output of both matching and non-matching
id's.
Below is the script I am using and can you kindly let me know where I
am doing wrong here?
================================
use strict;
use warnings;
open (IN1, "c:\test1.txt") || die "Can not open the file: $!";
open (IN2, "c:\test2.txt") || die "Can not open the file: $!";
open (OUT1, ">$dir1\\matching.txt") || die "Can not write to the
file: $!";
open (OUT2, ">$dir1\\not_matching.txt") || die "Can not write to the
file: $!";
@array1 = <IN1>;
@array2 = <IN2>;
foreach $record1 (@array1)
{
chomp $record1;
@fields1= split /\t/, $record1;
$fist_id = $fields1[0];
}
foreach $record2 (@array2)
{
chomp $record2;
@fields2= split /\t/, $record2;
$second_id = $fields2[0];
foreach (@fields1)
{
if ($second_id eq $fist_id)
{
print OUT1 "$record2\n" ; # matching
}
else
{
print OUT1 "$record2\n" ; # matching
}
}
close (IN1);
close (IN2);
close (OUT1);
close (OUT2);
+++++++++++++++++++++++++++++++++++++
Thanks in advance,
JC
file has 4 fields and the second one has two fields, but both files
have the "user_id" as the first field.
Example:
c:\test1.txt
=================
jcarter john (e-mail address removed) mstella
mstella mary (e-mail address removed) bborders
msmith martin (e-mail address removed) mstella
bborders bob (e-mail address removed) rcasey
swatson sush (e-mail address removed) mstella
rcasey rick (e-mail address removed) rcasey
c:\test2.txt
======================
aaboss active
jcarter active
msmith non-active
ssullivan non-active
rcasey non-active
usmiths active
===============================================
Now I want to check if each id from the second file exists in the
first one or not. I want the output of both matching and non-matching
id's.
Below is the script I am using and can you kindly let me know where I
am doing wrong here?
================================
use strict;
use warnings;
open (IN1, "c:\test1.txt") || die "Can not open the file: $!";
open (IN2, "c:\test2.txt") || die "Can not open the file: $!";
open (OUT1, ">$dir1\\matching.txt") || die "Can not write to the
file: $!";
open (OUT2, ">$dir1\\not_matching.txt") || die "Can not write to the
file: $!";
@array1 = <IN1>;
@array2 = <IN2>;
foreach $record1 (@array1)
{
chomp $record1;
@fields1= split /\t/, $record1;
$fist_id = $fields1[0];
}
foreach $record2 (@array2)
{
chomp $record2;
@fields2= split /\t/, $record2;
$second_id = $fields2[0];
foreach (@fields1)
{
if ($second_id eq $fist_id)
{
print OUT1 "$record2\n" ; # matching
}
else
{
print OUT1 "$record2\n" ; # matching
}
}
close (IN1);
close (IN2);
close (OUT1);
close (OUT2);
+++++++++++++++++++++++++++++++++++++
Thanks in advance,
JC