awk Built-in Variables NF - Number of Fields

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any awk Question?