Sponsored Content
Top Forums Shell Programming and Scripting GetLine fn always giving last line of the file Post 302594497 by hyperion.krish on Tuesday 31st of January 2012 12:19:34 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
srec_intel16(5) 						File Formats Manual						   srec_intel16(5)

NAME
srec_intel16 - Intel Hexadecimal 16-bit file format specification DESCRIPTION
This format is also known as the INHX16 format. This document describes the hexadecimal object file format for 16-bit microprocessors. This format is very similar to the srec_intel(5) format, except that the addresses are word addresses. The count field is a word count. The hexadecimal representation of binary is coded in ASCII alphanumeric characters. For example, the 8-bit binary value 0011-1111 is 3F in hexadecimal. To code this in ASCII, one 8-bit byte containing the ASCII code for the character '3' (0011-0011 or 0x33) and one 8-bit byte containing the) ASCII code for the character 'F' (0100-0110 or 0x46) are required. For each byte value, the high-order hexadecimal digit is always the first digit of the pair of hexadecimal digits. This representation (ASCII hexadecimal) requires twice as many bytes as the binary representation. A hexadecimal object file is blocked into records, each of which contains the record type, length, memory load address and checksum in addition to the data. There are currently six (6) different types of records that are defined, not all combinations of these records are meaningful, however. The record are: o Data Record o End of File Record o Extended Segment Address Record o Start Segment Address Record o Extended Linear Address Record o Start Linear Address Record General Record Format +-------+--------+--------+--------+--------+--------+ |Record | Record | Load | Record | Data | Check | |Mark | Length | Offset | Type | | sum | +-------+--------+--------+--------+--------+--------+ Record Mark. Each record begins with a Record Mark field containing 0x3A, the ASCII code for the colon (":") character. Record Length Each record has a Record Length field which specifies the number of 16-bit words of information or data which follows the Record Type field of the record. This field is one byte, represented as two hexadecimal characters. The maximum value of the Record Length field is hexadecimal 'FF' or 255. Load Offset Each record has a Load Offset field which specifies the 16-bit starting load offset of the data words, therefore this field is only used for Data Records (if the words are loaded as bytes, the address needs to be doubled). In other records where this field is not used, it should be coded as four ASCII zero characters ("0000" or 0x30303030). This field one 16-bit word, represented as four hexadecimal characters. Record Type Each record has a Record Type field which specifies the record type of this record. The Record Type field is used to interpret the remaining information within the record. This field is one byte, represented as two hexadecimal characters. The encoding for all the current record types are: 0 Data Record 1 End of File Record 5 Execution Start Address Record Data Each record has a variable length Data field, it consists of zero or more 16-bit words encoded as set of 4 hexadecimal digits, most significant digit first. The interpretation of this field depends on the Record Type field. Checksum Each record ends with a Checksum field that contains the ASCII hexadecimal representation of the two's complement of the 8-bit bytes that result from converting each pair of ASCII hexadecimal digits to one byte of binary, from and including the Record Length field to and including the last byte of the Data field. Therefore, the sum of all the ASCII pairs in a record after converting to binary, from the Record Length field to and including the Checksum field, is zero. Data Record (8-, 16- or 32-bit formats) +-------+--------+--------+--------+--------+--------+ |Record | Record | Load | Record | Data | Check | |Mark | Length | Offset | Type | | sum | |(":") | | | | | | +-------+--------+--------+--------+--------+--------+ The Data Record provides a set of hexadecimal digits that represent the ASCII code for data bytes that make up a portion of a memory image. The contents of the individual fields within the record are: Record Mark This field contains 0x3A, the hexadecimal encoding of the ASCII colon (":") character. Record Length The field contains two ASCII hexadecimal digits that specify the number of 16-bit data words in the record. The maximum value is 255 decimal. Load Offset This field contains four ASCII hexadecimal digits representing the word address at which the first word of the data is to be placed. (For an exquivalent bytes address, double it.) Record Type This field contains 0x3030, the hexadecimal encoding of the ASCII character "00", which specifies the record type to be a Data Record. Data This field contains sets of four ASCII hexadecimal digits, one set for each 16-bit data word, most significant digit first. Checksum This field contains the check sum on the Record Length, Load Offset, Record Type, and Data fields. Execution Start Address Record +-------+--------+--------+--------+--------+--------+ |Record | Record | Load | Record | EIP (4 | Check | |Mark | Length | Offset | Type | bytes) | sum | |(":") | (4) | (0) | (5) | | | +-------+--------+--------+--------+--------+--------+ The Execution Start Address Record is used to specify the execution start address for the object file. This is where the loader is to jump to begin execution once the hex load is complete. The Execution Start Address Record can appear anywhere in a hexadecimal object file. If such a record is not present in a hexadecimal object file, a loader is free to assign a default execution start address. The contents of the individual fields within the record are: Record mark This field contains 0x3A, the hexadecimal encoding of the ASCII colon (":") character. Record length The field contains 0x3032, the hexadecimal encoding of the ASCII characters "02", which is the length, in bytes, of the EIP regis- ter content within this record. Load Offset This field contains 0x30303030, the hexadecimal encoding of the ASCII characters "0000", since this field is not used for this record. Record Type This field contains 0x3035, the hexadecimal encoding of the ASCII character "05", which specifies the record type to be a Start Address Record. EIP This field contains eight ASCII hexadecimal digits that specify the address. The field is encoded big-endian (most significant digit first). Checksum This field contains the check sum on the Record length, Load Offset, Record Type, and EIP fields. End of File Record This shall be the last record in the file. +-------+--------+--------+--------+--------+ |Record | Record | Load | Record | Check | |Mark | Length | Offset | Type | sum | |(":") | (0) | (0) | (1) | (0xFF) | +-------+--------+--------+--------+--------+ The End of File Record specifies the end of the hexadecimal object file. The contents of the individual fields within the record are: Record mark This field contains 0x3A, the hexadecimal encoding of the ASCII colon (":") character. Record Length The field contains 0x3030, the hexadecimal encoding of the ASCII characters "00". Since this record does not contain any Data bytes, the length is zero. Load Offset This field contains 0x30303030, the hexadecimal encoding of the ASCII characters "0000", since this field is not used for this record. Record Type This field contains 0x3031, the hexadecimal encoding of the ASCII character "01", which specifies the record type to be an End of File Record. Checksum This field contains the check sum an the Record Length, Load Offset, and Record Type fields. Since all the fields are static, the check sum can also be calculated statically, and the value is 0x4646, the hexadecimal encoding of the ASCII characters "FF". Size Multiplier In general, binary data will expand in sized by approximately 2.3 times when represented with this format. EXAMPLE
Here is an example INHX16 file. It contains the data "Hello, World" to be loaded at address 0. :0700000065486C6C2C6F5720726F646CFF0AA8 :00000001FF COPYRIGHT
srec_cat version 1.58 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Peter Miller The srec_cat program comes with ABSOLUTELY NO WARRANTY; for details use the 'srec_cat -VERSion License' command. This is free software and you are welcome to redistribute it under certain conditions; for details use the 'srec_cat -VERSion License' command. AUTHOR
Peter Miller E-Mail: pmiller@opensource.org.au //* WWW: http://miller.emu.id.au/pmiller/ Reference Manual SRecord srec_intel16(5)
All times are GMT -4. The time now is 11:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy