GetLine fn always giving last line of the file

Hi,

Its bit urget for me to complete. pls help me.

I am parsing 2 file 1. INDATA(Data file) 2. GRPFIL(Reference)

every record in INDATA should be verified with GRP_DATA.

I am seeing the output from only the last line of ref file, its not searching all the lines.

 
INDATA sample
10/11�PAID�BCBSMAN�9893�37402�7086191�RETAIL�00002-1975-90�B�88�30�1�278.15�-0.45�1.5�334.32�30�30�YES
10/11�APM�RX1004�4336�139�8944310�RETAIL�00002-1975-90�B�30�30�1�287.09�8.49�1.25�334.32�30�30�YES
10/11�APM�HNET�800001�5649�1500568�RETAIL�00002-1975-90�B�30�30�2�579.1�21.9�3�668.64�30�60�YES
10/11�APM�53459P�11834�250�18581�RETAIL�00002-1975-90�B�60�30�1�583.33�26.13�2�668.64�60�60�YES
10/11�PCS�VS�600428�544�35288�MAIL�00002-1975-90�B�30�30�1�292.99�14.39�1.9�334.32�30�30�YES
10/11�PCSMO�SMHSMRCY�610029�673�2726429�MAIL�00002-1975-90�B�30�30�1�278.99�0.39�1.5�334.32�30�30�YES
10/11�RSTAT�202�610029�673�1361974�MAIL�00002-1975-90�B�30�30�5�1398.29�5.29�7.5�1671.6�30�150�YES
10/11�PAIDMPD�NONE�600428�44539�7970084�NONE�00002-1975-90�B�30�30�1�292.99�14.39�1.9�334.32�30�30�YES
10/11�PCS�2407�11552�1427�335281�MAIL�00002-1975-90�B�30�30�1�289.55�10.95�1.5�334.32�30�30�YES
 
GRP_DATA
-----------
Caloptima�PERXMPD�WM4A�NONE�Caloptima�N�CalOptima�NO MAIL�MCO
Caloptima MPD�PERXMPD�WM5A�NONE�Caloptima�YES�CalOptima Medicare Part D�NO MAIL�MCO
BCBS of MI�PAIDMPD�BCNRXPD�NONE�BCBS of Michigan�YES�Michigan Blue Cross / Paid�BCBS of Michigan�MCO
 
#Include File for Environment variable usage
. /opt/hyperion/Payer_Transformation/Scripts/PayersTrnEnv.env
#Defining Log file for this treatment
rm ${OUT_DATA}
awk 'BEGIN {
        FS = "�"
  OFS = "|"
  i=1}
  {
   if ( $7 == "RETAIL" )
   {
    Tar_Loc=$7
    if ( $9 -le 83 )
     Tar_Lob="RETAIL30";
     else Tar_Lob ="RETAIL90";
   }
   if ( $7 == "MAIL" )
   { 
   Tar_Loc=$7; 
   Tar_Lob="MAIL";
    if ( $2 ~ /PCS/ )
     { if ( $3 ~ /V/ )
      {Group_ID="V";}
      else if ($3 ~ /2407/ || $3 ~ /2428/) 
       {Group_ID="HME";}
     }
   }   
  while (e = (getline grp < "'$GRP_DATA'") > 0){
  #while( getline grp < "'$GRP_DATA'" )
  split(grp, grpfield, "�")
  f0=grpfield[0]
  f1=grpfield[1]
  f2=grpfield[2]
  f3=grpfield[3]
  f4=grpfield[4]
  print '"i++"', f0, f1, f2, f3, f4; 
  if ( grpfield[2] == $2 && grpfield[3] == Group_ID && grpfield[4] == $7 ){
   Tar_Grp_Nam=grpfield[1];
   close ("'$GRP_DATA'");
   break;
   #print '"i++"',Tar_Grp_Nam,f4,$7;
   }
  else if ( grpfield[2] == $2 && grpfield[3] == Group_ID && $7 != "MAIL"){
   Tar_Grp_Nam=grpfield[1];
   close ("'$GRP_DATA'");
   break; }  
   #print '"i++"',Tar_Grp_Nam,f4,$7;
  #close ("'$GRP_DATA'"); 
  }
  if(e < 0) print "Error Reading";
  
  Tar_Mon=$1
  Tar_Year=$1
  Tar_Num_Rxs=$12
  Tar_Tot_Rev=$13
  Tar_GP_Wac=$14
  print $1,$2,f2,Tar_Grp_Nam,f1,Group_ID,f3,f4,$7;
  } ' $IN_DATA > $OUT_DATA
 

Each record from IN DATA shoude be validated agains the GRP DATA (ref file)

Hi, next time please put code tags and properly indent your code, so it is easier to read

print $1,$2,f2,Tar_Grp_Nam,f1,Group_ID,f3,f4,$7;

is outside the while loop, so it will always report the values of the last line, of the group file, after all the lines of the group file will have been read.