perlquestion
Divakar
<p>Hi Folks,</p>
<p>i have 2 files (file1.txt and file2.txt). i have to check which things are newly added in file2.txt.
so i am using grep function to check whether it is already there. but it is not matching exact string.
anyone have any idea?
</p>
<p>
file1.txt contains
<code>
nt64osbld2tmp
vm-nt64osbld2
vm-nt64osbld3
vm-nt64osbld4
vm-nt64osbld5
vm-nt64osremot1
vm-nt64osremot2
vm-nt64osremot3
vm-nt64osremot4
vm-nt64osremot5
vm-nt64osremot6
vm-nt64osremot7
vm-nt64osremot8
vm-ntdivakar1
vm-ntdivakar2
vm-ntdivakar4
vm-ntosbld1
vm-ntosbld5
vm-ntoscert3
vm-ntosdev1
vm-ntskommare1
vm-ntskommare2
vm-ntskommare4
vm-os2k8r264-01
vm-osremote1
vm-osremote10
vm-osremote2
vm-osremote3
vm-osremote4
vm-osremote5
vm-osremote6
vm-osw2k8-1
vm-osw2k8-2
vm-oswin2k3-32
vm-oswin2k3-64
</code>
</p>
file2.txt contains
<code>
nt64osbld2
nt64osbld2tmp
nt64osbld3
nt64oscitrix1
NTOSBLD4
ntosbld5
ntosbld6
VM-NT64OSBLD2
VM-NT64OSBLD3
VM-NT64OSBLD4
VM-NT64OSBLD5
vm-nt64osremot1
vm-nt64osremot2
vm-nt64osremot3
vm-nt64osremot4
vm-nt64osremot5
vm-nt64osremot6
VM-NT64OSREMOT7
VM-NT64OSREMOT8
vm-ntosbld1
VM-NTOSBLD5
vm-ntoscert3
vm-ntosdev1
VM-OS2K8R264-01
vm-osremote1
vm-osremote10
vm-osremote2
vm-osremote3
vm-osremote4
VM-OSREMOTE5
vm-osremote6
VM-OSW2K8-1
VM-OSW2K8-2
VM-OSW2K8X64-1
VM-OSW2K8X64-2
VM-OSWIN2K3-32
VM-OSWIN2K3-64
</code>
<p>
</p>
below is my script.
<code>
use warnings;
use strict;
my @first_list;
my @second_list;
my @first_list_new;
my @second_list_new;
open FIRST_LIST, "< first_list.txt" or print $! "\n";
@first_list=<FIRST_LIST>;
close (FIRST_LIST);
chomp (@first_list);
open SECOND_LIST, "< second_list.txt" or print $! "\n";
@second_list=<SECOND_LIST>;
close (SECOND_LIST);
chomp (@second_list);
foreach my $machine (@first_list)
{
my $machine_new=lc($machine);
push(@first_list_new,$machine_new);
}
foreach my $machine (@second_list)
{
my $machine_new=lc($machine);
push(@second_list_new,$machine_new);
}
print "Machines extra in second list\n\n";
foreach my $unique (@second_list_new)
{
if (grep (/^$unique$/,@first_list_new))
{
print "already there $unique\n\n";
}
else
{
print "newly in this $unique\n\n";
}
}
</code>
<p>Thanks & Regards,</p>
<p>Divakar</p>