Counting number of commas(,) in a variable

Hi all,

I am having problems counting commas (,) from a variable in shell scripting..

the variable contains similiar to: ID@NAME@DESCRIPTION,ID@NAME@DESCRIPTION, .....
It can go on and on..

So i need to count the number of sets i.e.( ID@NAME@DESCRIPTION is one set) and process the informattion in them.

Does anyone knows how to count the number of commas in this example? or is there any other sleek method to do this =)

Something like this?

echo $var | awk -F, '{print NF-1}'
var='ID@NAME@DESCRIPTION,ID@NAME@DESCRIPTION, .....'
printf "%s\n" "$var" | awk '{ print gsub(/,/,"") }'

Or, in bash or ksh93:

x=${var//[!,]/}
echo "${#x}"

hmm i get it working!~ thanks.

after i counted the comma(s),

i store the value into COUNT variable and do a while loop
and also, var='ID@NAME@DESCRIPTION,ID@NAME@DESCRIPTION, .....'

i also wanted to extract each individual person info out based on the commas between them.

But, somehow, the awk function print $i can't work.
the value stored in the $person is still the same as $var

i=0
while [ $i -le $COUNT ] ; do
        i=`expr $i + 1`
        person=`echo $var | awk 'BEGIN { FS = "," } ; { print $($i) }'`
        process each person..

---------- Post updated at 11:34 PM ---------- Previous update was at 11:06 AM ----------

anyone knows how to solve?

$
$ echo "i1@n1@d1,i2@n2@d2,i3@n3@d3" |perl -nle 'chomp; split/,/; foreach $i(@_){print $i}'
i1@n1@d1
i2@n2@d2
i3@n3@d3
$

tyler_durden