Here's one way to do it in a shell script:
Code:
head -1 myfile.csv|awk -F, '{print NF}'
"head -1 myfile.csv" lists only the first line in your CSV file. We pipe that line to "awk".
"-F," tells awk to separate fields using a comma (",") instead of a space or a tab.
NF is a built-in variable containing the #/fields in this line (i.e. #/columns in your file).
The output from your example would be "3".
Here's a good tutorial on bash scripting (one of many!):
http://www.freeos.com/guides/lsst/
Unfortunately, shell scripting isn't something you can "just learn" (by reading a book or a tutorial), because it's less about learning the syntax of a specific language ("bash" or "ksh") than it is about learning how to use all the different tools in the environment (sed, awk, cut, paste, etc etc) effectively.
Fortunately, getting started is easy (the basics are really simple), and gaining proficiency is fun (the more you play with it, the more you want to learn more).
IMHO .. PSM