awk - counting the occurrences of a field on a individual line -


I am trying to take a file that has several 1000 lines, and for each line I would like to count the incidents If there are areas, then the example of some lines of file looks like this:

  0/0 0/0 0/0 0/0/0/0/0 0/0 0/1 0/0 0/0 1/1 0/0 0/1 0/1 1/1 0/1 0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0 0 0 < / Code> 

My code is:

  cat file | Awk 'BEGIN {a = 0; C = 0; G = 0;} {a + = gsub ("0/0", ""); C + = gsub ("0/1", ""); G + = gsub ("1/1", "")} END {print a, c, g} ' 

The output I get:
18 4 2

I think the output is:

  line # 1- 9 2 1 line # 2- 9 2 1  

I

  awk '{print "line #" , Nr, "-", gsub ("0/0", ""), gsub ("0/1", ""), gsub ("1/1", "")} 'file  Pre> 

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -