0

I have a file that come from map reduce output for the format below that needs conversion to CSV using shell script . The dynamic values are five values and they are the transaction IDs and the four fields(2000,ABC corp,.., BE900000075000027) after that and they keep changing for the next Transaction ID , only the other 17 values(25-MAY-15,04:20 ...til standard life) is constant.

25-MAY-15
04:20
Client
0000000010
127.0.0.1
PAY
ISO20022
PAIN000
100
1
CUST
API
ABF07
ABC03_LIFE.xml
AFF07/LIFE
100000
Standard Life 

================================================
================================================

AFF07-B000001

 2000

ABC Corp
..

BE900000075000027


AFF07-B000002

 2000

XYZ corp
..

BE900000075000027



AFF07-B000003

 2000

3MM corp
..

BE900000075000027

Need output in below format

25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,ABF07,ABC03_LIFE.xml,AFF07/LIFE,100000,Standard Life, 25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,AFF07-B000001, 2000,ABC Corp,..,BE900000075000027

25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,ABF07,ABC03_LIFE.xml,AFF07/LIFE,100000,Standard Life, 25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,AFF07-B000002,2000,XYZ Corp,..,BE900000075000027

I need values to be repeating just before the two dashed lines along with the rest of the output for the Transaction ID AFF07-B000001,AFF07-B000002,AFF07-B000003 There is no dash lines in the real file , I have added it to ensure a better understanding of the input file

1 Answer 1

1

assuming there are 5 field to be repeated, use following awk

BEGIN { header=1 ; }
length($0) == 0 { header=0 }
length($0) > 0 {
    if ( header ) { str_h= str_h "," $0 ;}
        else {
        str_f = str_f "," $0 ;
        c++ ;
            if ( c == 5 ) {
               printf "%s%s\n",substr(str_h,2),str_f ;
               c = 0 ;
               str_f = "" ;
            }
         }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .