Search and Replace between two files

Hi all-
I've got 2 files: One is the final results and one is a result set from a query.

In the final results files I have placeholder strings in there that need to be replaced by the corresponding strings from the query file.

So File#1 (FINAL RESULTS)

LINEID   CLIENT   ID       REP     DATE              NUM    TYPE
3452a   000001   IDENT   54787  STARTDATE    NUM      TYPCODE
asd54   000001   IDENT   54799  STARTDATE    NUM      TYPCODE
asd6a   000231   IDENT   55781  STARTDATE    NUM      TYPCODE
sdf57   004578   IDENT   87787  STARTDATE    NUM      TYPCODE
sd5f6   004578   IDENT   94787  STARTDATE    NUM      TYPCODE
df57r   000044   IDENT   34787  STARTDATE    NUM      TYPCODE
jhe21   007777   IDENT   55777  STARTDATE    NUM      TYPCODE
jra48   000111   IDENT   54787  STARTDATE    NUM      TYPCODE

File#2 (Look up)

CLIENT   ID       DATE              NUM    TYPE
000001   222     6/30/09          A23       I
000231   352     6/3/09           A26       P
004579   272     6/1/09           A24       A
000044   992     5/20/09          A23       I
007777   228     1/30/09          A27       A
000111   201     4/27/09          A23       I

So I want to search for matching the CLIENT value and replace the placeholders in file #1(IDENT, STARTDATE,NUM,TYPCODE) with the correct values from file #2

Any ideas?

if you do not know the sequence of your ID/DATE/..., and have to base on header sequence to decide, then below complicated perl may help you some.

But is you already know the sequence of header part and can use before script, then modify below accordingly to a easy one.

my(%hash,%result,%hash1);
open $fh,"<","lookup.txt';
while(<$fh>){
	chomp;
	my @tmp=split;
	if($.==1){
		for(my $i=1;$i<=$#tmp;$i++){
			$hash{$tmp[$i]}=$i;
		}
	}
	else{
		my $client=$tmp[0];
		for(my $j=1;$j<=$#tmp;$j++){
			$result{$client}->{$j}=$tmp[$j];
		}
	}
}
close $fh;
open $fh,"<","final.txt";
while(<$fh>){
	chomp;
	my @tmp=split;
	for(my $i=2;$i<=$#tmp;$i++){
		if($.==1){
			$hash1{$i}=$tmp[$i];
		}
		else{
			$tmp[$i]=($result{$tmp[1]}->{$hash{$hash1{$i}}})?$result{$tmp[1]}->{$hash{$hash1{$i}}}:$tmp[$i];
		}
	}
	print join " ", @tmp;
	print "\n";
}