How to Count the number of column in a csv file

Simple and easy way to count the columns in cvs files in Linux using sed utility. Ous csv file is called data.csv and contains the following

1,1,1
2,2,2
3,3,3
 Count the numbers of columns.
[dbadmin@hosttmp]$ head -1 /tmp/data.csv
1,1,1

-- use sed utility
[dbadmin@hosttmp]$ head -1 /tmp/data.csv | sed 's/[^,]//g'| wc -c
3
Done Also as we can use awk for this task as Robert McAllister stated.
-- use sed utility
[dbadmin@host tmp]$ head -1 /path/to/file.csv | awk -F, '{print NF}'
3