GetLine fn always giving last line of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GetLine fn always giving last line of the file
# 1  
Old 01-31-2012
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.
Code:
 
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)

Last edited by jim mcnamara; 01-31-2012 at 06:26 PM.. Reason: code tags
# 2  
Old 01-31-2012
Hi, next time please put code tags and properly indent your code, so it is easier to read
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk getline 8 times and if $3 = 8 when subtracted from 1st line,print

I have kind of a strange one here. I have a file of consecutive /24 ip blocks. If there are 8 consecutive ip blocks which represent a /20 then I need to print the first line. I played around and did not get the results I need, especially when considering that the highest $3 will be is 255 and then... (6 Replies)
Discussion started by: numele
6 Replies

2. Shell Programming and Scripting

wc -L giving incorrect length of longest line

Running below line gives 3957 as length of longest line in file 20121119_SRMNotes_init.dat awk ' { if ( length > 3950 ) { x = length } }END{ print x }' 20121119_SRMNotes_init.dat While wc -L 20121119_SRMNotes_init.dat gives output as 4329. Why is there a difference between these two commands.... (2 Replies)
Discussion started by: Satish Mantha
2 Replies

3. Shell Programming and Scripting

awk getline t file

I want to import a textfile with getline into var t which has several lines. How do import all lines, since it only imports the last line: while < ((getline t "textfile") > 0) (7 Replies)
Discussion started by: sdf
7 Replies

4. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

5. Shell Programming and Scripting

getline from another file

Here is I want to do: find lines in file filteredtrace.txt which is not continued as a multiply of 4 and strip them from file original_trace_framno. problem is awk used the ' symbol so pipe of getline has to use the " symbol while agument of sed has to use the " symbol, it doesn't... (8 Replies)
Discussion started by: lzq420241
8 Replies

6. Shell Programming and Scripting

awk - getline from parametric file name

Hi! I have an input file for an awk script that I need to split into several files and the process them separately line by line. I have splitted the input file into the other files, that have been created correctly. But, since their names are parametric (i.e. output_1.txt, output_2.txt..... (2 Replies)
Discussion started by: Alice236
2 Replies

7. Shell Programming and Scripting

Giving format to a file

hi all, i have a big problem and i don't know what to do. This is the thing: i have a flat file with 26 fields, which are separated by ';' by example, i have this: Peter;Smith;2005;200508; ......... if the lengths of the fields are: field 1: Alphanumeric - field 2: Alphanumeric - field... (4 Replies)
Discussion started by: DebianJ
4 Replies

8. Solaris

^p not giving command line history.

I am used to using "set -o emacs" and then using "CNTL-P" for getting previous commands in solaris but on one host it does not work and instead just makes a DONG!! # ksh # set -o emacs # ls # ^p Can anyone offer guidance as to why this is? Thank you my friends. akbar (0 Replies)
Discussion started by: akbar
0 Replies

9. Shell Programming and Scripting

Giving input to a c++ file

My C++ program creates a nxn matrix with given value. For e.g if the input is 10 it will creates a matrix of 10x10 now what i want is the script should run program and give input values in a variation of 1000. Say first matrix of 1000 then 2000 , 3000 ..... 10000. I tried using for loop but unable... (2 Replies)
Discussion started by: tonyaim83
2 Replies

10. Shell Programming and Scripting

using the getline to populate an array from a file

Hello, I am trying to use the awk getline command to populate an array from a flat file. Has anyone done this before? So we have file1: a b c d I want to create an array like index that contains these four elements (8 Replies)
Discussion started by: penfold
8 Replies
Login or Register to Ask a Question