awk NF - Number of Fields


Example

Provides the number of columns or fields in each record (record corresponds to each line). Each line is demarcated by RS which defaults to newline.

cat > file1
Harley Quinn Loves Joker
Batman Loves Wonder Woman
Superman is not dead
Why is everything I type four fielded!?

awk '{print NF}' file1
4
4
4
7

FS (somewhere up there) defaults to tab or space. So Harley, Quinn, Loves, Joker are each considered as columns. The case holds for the next two lines, but the last line has 7 space separated words, which means 7 columns.