Count number of ';' in column

Ops :

I use the following command to count number of ; in a first line in a file:

awk -F';' '(NR==1){print NF;}' $filename

I would like to do same with all lines in the same file. That is to say, count number of ; on all line in file.

What I have :

$ awk -F';' '(NR==1){print NF;}' $filename
11

What I would like to have :

11
11
11
11
11
11
RavinderSingh13 :

Straight forward method to count ; per line should be:

awk '{print gsub(/;/,"&")}' Input_file

To remove empty lines try:

awk 'NF{print gsub(/;/,"&")}' Input_file

To do this in OP's way reduce 1 from value of NF:

awk -F';' '{print (NF-1)}' Input_file

OR

awk -F';' 'NF{print (NF-1)}' Input_file

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=12190&siteId=1