C
clearguy02
Hi folks,
I have two files:
a.txt has 100 unique log_id's (one id per line);
all.txt has 5000 entries (each line has six entries seperated by a
tab and the first entry on each line is the login ID and then full
name, country etc).
Now I want to match both files and get the output with all 100 full
entries and ignore the rest.
Here is the code I am working on.. for some reason, I see more 160
entries instead of the exact 100 entries.
++++++++++++++++++++
my %myconfig = (
input1 => 'a.txt',
input2 => 'all.txt',
matching => 'required.txt',
non_matching => 'ignore.txt',
);
my %fields2;
{
open my $input, '<', $myconfig{input1} or die "Cannot open
'$myconfig{input1}': $!";
while ( <$input> )
{
if ( /^(\w+)/ )
{
$fields2{ $1 } = 1;
}
}
close $input or die "Cannot close '$myconfig{input1}': $!";
}
open my $input, '<', $myconfig{input2} or die "Cannot open
'$myconfig{input2}': $!";
open my $matching, '>', $myconfig{matching} or die "Cannot open
'$myconfig{matching}': $!";
open my $non_matching, '>', $myconfig{non_matching} or die "Cannot
open '$myconfig{non_matching}': $!";
while ( <$input> )
{
if ( /^(\w+)/ )
{
if ( exists $fields2{ $1 } )
{
print $matching "$_\n";
}
else
{
print $non_matching "$_\n";
}
}
}
++++++++++++++++++++++++++++++++++++
What I am doing wrong here? Or is there any alternative way of doing
it?
Thanks,
J
I have two files:
a.txt has 100 unique log_id's (one id per line);
all.txt has 5000 entries (each line has six entries seperated by a
tab and the first entry on each line is the login ID and then full
name, country etc).
Now I want to match both files and get the output with all 100 full
entries and ignore the rest.
Here is the code I am working on.. for some reason, I see more 160
entries instead of the exact 100 entries.
++++++++++++++++++++
my %myconfig = (
input1 => 'a.txt',
input2 => 'all.txt',
matching => 'required.txt',
non_matching => 'ignore.txt',
);
my %fields2;
{
open my $input, '<', $myconfig{input1} or die "Cannot open
'$myconfig{input1}': $!";
while ( <$input> )
{
if ( /^(\w+)/ )
{
$fields2{ $1 } = 1;
}
}
close $input or die "Cannot close '$myconfig{input1}': $!";
}
open my $input, '<', $myconfig{input2} or die "Cannot open
'$myconfig{input2}': $!";
open my $matching, '>', $myconfig{matching} or die "Cannot open
'$myconfig{matching}': $!";
open my $non_matching, '>', $myconfig{non_matching} or die "Cannot
open '$myconfig{non_matching}': $!";
while ( <$input> )
{
if ( /^(\w+)/ )
{
if ( exists $fields2{ $1 } )
{
print $matching "$_\n";
}
else
{
print $non_matching "$_\n";
}
}
}
++++++++++++++++++++++++++++++++++++
What I am doing wrong here? Or is there any alternative way of doing
it?
Thanks,
J