The sequence of output file Should be in accordance to File 1. If any Value of File 1 is not found in File 2 then second field
of Output file should be a blank.
I cannot use grep command in for loop as the number of entries in File 1 is about 5000 and that in File 2 is 900,000.
Thanks but it is taking lot of time to execute and I am afraid I cannot devote that much of time. So If u could please suggest another solution which gives an output faster than this one.
And Please could u explain how the code u have given works.
my bad. i missed the 900000 records. well how about trying something else. if you have Python, this is an alternative:
data=open("file1").readlines() #read file1 into array
data=[i.strip() for i in data] #get rid of newlines
for line in open("file2"): #process file2 line by line
if line[0:3] in data: #check only first 3 characters
print line,
else: print "%s|" % line[0:3]
sorry, i don't code perl, but roughly the method is same.
not tested code:
open(file1,"<","file1") or die "cannot open file1:$!";
#get file1 into array
while ( <file1> ) {
push @file1, chomp($_);
}
open(file2,"<","file2") or die "cannot open file2:$!";
#go through every line in file2
while ( my $line = <file2> ) {
chomp($line);
# get the first 3 characters, check if its in file1 array, if yes print
if ( exists $file1[substr($line,0,3)] ) {
print $line;
}
}
close(file1);
close(file2);