awk NF - Number of Fields


Example

This variable will give you a total number of fields in the current input record.

awk -F',' '{print NF}' file.csv

Example:

$ cat file.csv 
col1,col2,col3,col4
col1,col2,col3
col1,col2
col1
col1,col2,col3,col4,col5
 
$ awk -F',' '{print NF}' file.csv 
4
3
2
1
5