Code:
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
}
'