How to find number of Cols in a file ?

Hi

I have a requirement wherein the file is comma separated. Each records seems to have different number of columns, how I can detect like a row index wise, how many columns are present ?

Thanks in advance.

Hope this helps,

count=0
while read LINE
do
let count=count+1
echo $LINE|awk -F, '{ print "Line : "'$count', "Columns : "NF }'
done < $file

or u can use this in command line,

awk -F, '{ print "Line : "FNR, "Columns : "NF }' file