count of null in pipe delimited txt file

Hi,

I have a pipe delimited txt file which contains 17 fields per line/row.
16th field contains email id. I want to count the number of lines/rows that contains null in the 16th field.

Plz find attached example data file.
I'm looking for a command line/script which achieves this.

Thanks,
Sri

awk -F"|" '$16==""{x++;}END{print x}' file

Guru.

1 Like

The following would also count 16th fields who are made of space

nawk -F\| '$16~/^ *$/{++c}END{print c}' exmple_data.txt
grep -c '||[^|]*$' file

Thanks Guru.... It works.
What if I have to take the count to a variable and use it in some calculation?

 
myvar=$(awk -F"|" '$16==""{x++;}END{print x}' file)
echo $myvar
1 Like