I've one EDI file which is to be parsed into 7 different file.
I managed to extract required segments for a file(HEADER) to a separate file(sample3.dat) and is given below.
$ cat sample3.dat
REF*EI*273543997~
REF*2U*HELLO~
REF*G2*77685|132~
CLM*1000*0.00***12>B>1*N*A*Y*I~
CN1*05~
SBR*P*18*HELLO******16~
AMT*D*0.00~
OI***Y***I~
NM1*IL*1*ABC*DEF*A***MI*1234A~
DTP*573*D8*99991231~
CLM*1001*0.00***12>B>1*N*A*Y*I~
CN1*05~
REF*F8*1000~
SBR*P*18*HELLO******16~
AMT*D*0.00~
OI***Y***I~
NM1*IL*1*ABC*DEF*A***MI*1234A~
DTP*573*D8*99991231~
Expected output is as below
1000||||1234A|1234A|0.00|99991231|0.00|||||HELLO||12|1|||||||||||||05|HELLO|
1001||||1234A|1234A|0.00|99991231|0.00|||||HELLO||12|1|||||||||||1000||05|HELLO|F8
Second CLM segment is the child claim of first CLM and REF segment is available under that. I wrote the below script to parse the file.
Commented portion of the script below throws syntax error.
awk -F"*" '{OFS="|"}
/^CLM/ {CLM_NBR = $2}
/^NM1/ {SUB_ID = $10}
/^AMT/ {($2=="D")? CP_AMT = $3 : CP_AMT = $100}
/^AMT/ {($2=="A8")? DSALL_AMT = $3 : DSALL_AMT = $100}
/^AMT/ {($2=="F5")? PATPAID_AMT = $3 : PATPAID_AMT = $100}
/^AMT/ {($2=="A8")? NC = $3 : NC = $100}
/^AMT/ {($2=="EAF")? RPL = $3: RPL = $100}
/^SBR/ {GRP_POL = $4; GRP_NM = $5}
/^CLM/ {split($6,x,">") ; FREQ = x[3]}
##/^CLM/ {split($6,x,">");(x[3]=="7"||x[3]=="8")? (/^REF\*F8/ {REP_CLM = $3;REF_QUAL = $2}) : {REP_CLM = $100;REF_QUAL = $100}}
REP_CLM = $100;REF_QUAL = $100 ## Temporarily assigned NULL value to be printed as above line throws syntax error
/^CN1/ {ICAP_IND = $2}
/^REF\*2U/ {($2=="2U")? HP = $3 : HP = $100}
/^DTP/ {($2 == "573")? PD_DATE = $4 : PD_DATE = $100
print CLM_NBR,$100,$100,$100,SUB_ID,SUB_ID,CP_AMT,
PD_DATE,"0\.00",DSALL_AMT,PATPAID_AMT,NC,RPL,
GRP_POL,GRP_NM,"12",FREQ,
$100,$100,$100,$100,$100,$100,$100,$100,$100,$100,
REP_CLM,$100,ICAP_IND,HP,REF_QUAL}' sample3.dat
Output after executing the file is given below
||.00|||||HELLO||12|1|||||||||100||||05~
||.00|||||HELLO||12|1|||||||||100||||05~
I don't understand where my script is going wrong. Can someone please help me in understanding this.
Thank you