Delimiter count

Hi I wrote shell script for count the deleimeters and send it to reject file
which are exeeseding number of count.
But script is not working properly...

Can you please check the below script and modify it as required.

ex :

1,abc
2,mno
3,pqr
4,xyz,error

As per the requiredment last record should go to reject file.

#!bin/ksh
i = aww
b = echo `awk -F , '{print NF-1}' $i`
for c in $b
do
if [ $c -ge 2];
then
echo $c >> $HOME/rejected_rocords
else
exit 0
fi
done
egrep -e '(,.*,)' filename

Your script will find and output the counts only, not the records. Instead of totally revising it, you may want to use jakanddaxter's proposal. For varying counts you could use (given your grep version allows for it)

grep -E '(.*,){2}' file > reject_file

and replace the 2 by the desired count.

Try

awk -F, 'NF==2{print}
         NF!=2{print $0 > "rejected_file"}' file