hi,
i am trying to parse a file in awk to generate a output to be written in a file depeding upon some condition. below is the code
Content of file1
919873741577,9131638459976206,20130715150109,S,919811000214,2A65,405899136999995
91225,9132019667696305,20130715150110,S,USSDLIKE,161A,405899136999995
54321,9132008640045585,20130715150109,S,SYMBIOTIC,2470,405899136999995
54321,9132008640041216,20130715150108,S,SYMBIOTIC,2458,405899136999995
54321,9132008640045246,20130715150109,S,SYMBIOTIC,2470,405899136999995
919865754417,9194*665665,20130715161714,F,2374,,919875089998
918926048523,911401727253,20130715141326,F,405899153999998,,919875089998
918640868045,911401727253,20130715165419,F,405899153999999,,919875089998
Code for parsing is as follows
awk -F, -v p2pcdr="file1" -v p2preject="P2P_REJ.txt"
' BEGIN{
while ((getline line < p2pcdr ) > 0 )
{
if ( $2 ~ "[*,#]" || ( ($2 + 0) !~ "^[0,5,7,8,9]") || length($2 + 0) <4 || ($2 !~ "^[0,5,7,8,9]"))
P2PREJECTCDR[line]
else if ( (length($6) == 13 || length($6) == 14 || length($6)==11) && !($6 ~ "^[A-Z,a-z]") )
P2PREJECTCDR[line]
else if ($6 =="" && substr($2,1,4)=="0091" && substr($2 + 0,3,1) !~ "^[1,2,5,7,8,9]")
P2PREJECTCDR[line]
else if ( $6 == "" && substr($2,1,2) == "00" && length($2) == "12" )
P2PCDR[$1,$2,$3,$4,$5,$2 + 0,$7]
else if ( $6 == "" && substr($2,1,1) == "0" && length($2) == "11" )
P2PCDR[$1,$2,$3,$4,$5,$2 + 0,$7]
else if ( $6 == "" && substr($2,1,3) == "+91" && length($2) == "13" )
P2PCDR[$1,$2,$3,$4,$5,substr($2,2,12),$7]
else if ( $6 == "" && substr($2,1,2) == "91" && length($2) == "12" && (substr($2,3,1) ~ "^[5,7,8,9]") )
P2PCDR[$1,$2,$3,$4,$5,$2,$7]
else if ($5 != "" && $6 != "")
P2PCDR[line]
else if ($5 == "" && $6 != "")
P2PCDR[line]
else if ($6 == "" && length($2)<=10 && length($2 + 0) >= 4 )
P2PCDR[$1,$2,$3,$4,$5,$2 + 0,$7]
else
P2PREJECTCDR[line]
} close (p2pcdr)
}
END
{
for ( counter in P2PCDR )
print counter >> "P2P.txt"
for ( counter in P2PREJECTCDR )
print counter >> p2preject
}
'
can you please help as this is not working
.