lookup in unix

Hi All
I have got a fixed length file of 80bytes long.The first 4bytes of each record represents a client_number.I need to modify the client number based on another lookup file.
The lookup file contains 2 fields and a comma delimited file.The first line of the lookup file contains the header information.

For example,
The lookup file has a path /data and the name of the file is client_nbr.lkp.The layout of the file is as follows.

From_Nbr,To_Nbr
1212,1100
1425,1233
1520,1400

The path of the original 80byte fixed length file is /temp.This file doesnot contain any header info.

1212.............................<80bytes>
1000.............................<80bytes>
1500.............................<80bytes>
1425.............................<80bytes>
1520.............................<80bytes>

The first 4 digits are client nbr.We have to do a lookup on /data/client_nbr file on From_Nbr field and if it matches the client_nbr will be replaced in the 80byte file with the To_Nbr value.
The final file should be located in /temp and the file name will remain same with only client_nbr info changed for some records where the lookup entry is available.

The final file should look like

1100.............................<80bytes>
1000.............................<80bytes>
1500.............................<80bytes>
1233.............................<80bytes>
1400.............................<80bytes>

Please help me wring a script which will take the 80byte fixed length file as a parameter as this name of the file varies on a daily basis but the content remains the same.

This should give the desired output, you can redirect the output to a new file:

awk 'BEGIN{FS=","}
{a[$1]=$2}
END {
  while((getline < "/temp/file") > 0 ) {
    if(substr($0,1,4) in a) {
      print a[substr($0,1,4)] substr($0,5)
    }
    else {
      print $0
    }
  }
}' "/data/client_nbr.lkp"

Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards

any suggestions how to do this ???

thanks a lot

i need to pass the input file name as a parameter and get the same file as the output after set operation

A variation on the theme....

nawk -f dr.awk client_nbr.lkp fixedLengthFile

dr.awk:

awk 'BEGIN{FS=","}
NR==FNR{a[$1]=$2; next}
{
   if (substr($0,1,4) in a)
      print a[substr($0,1,4)] substr($0,5)
   else
      print $0
}