title: Calculating ratio value within a line which contain binary numbers "0" & "1"
body: <p>I have a data file which contain more than 2000 lines and 45001 columns.</p>
  
  <p>The first column is actually a "string" which explains the data type.</p>
  
  <p>Start from column #2, up to column #45001, the data is reprsented as </p>
  
  <blockquote>
    <p>"1"</p>
  </blockquote>
  
  <p>or </p>
  
  <blockquote>
    <p>"0"</p>
  </blockquote>
  
  <p>For example, the pattern of data in a line is</p>
  
  <blockquote>
    <p>(0 0 0 <code>1 1</code> 0 <code>1 1 1</code> 0  <code>1 1 1 1</code> 0 0 0 <code>1</code> 0 0 <code>1 1 1</code> 0 0)</p>
  </blockquote>
  
  <p>The total number of data is 25. Within this data line, there are 5 sub-groups which are made by only the number "1"s e.g. (<code>11</code> <code>111</code> <code>1111</code> <code>1</code> <code>111</code> ). The "0"s in between the subgroups are assumed as "delimiter". The total of all "1"s is = 13. </p>
  
  <p>I would like to calculate the ratio of </p>
  
  <blockquote>
    <p>(total of all "1"s / total of number of sub-groups made only by "1"s)</p>
  </blockquote>
  
  <p>That is </p>
  
  <blockquote>
    <p>(13/5).</p>
  </blockquote>
  
  <p>I tried with this code for calculating the total of all "1"s ; </p>
  
  <pre><code>awk -F '0' '{print NF}' &lt; inputfile.in
  </code></pre>
  
  <p>This gives value 13.</p>
  
  <p>But I donn't know how to go further from here to calcuate the ratio that I want.
  I don't know how to find the number of sub-groups within each line beacuse the number of occurances of "1"s and "0"s are random.</p>
  
  <p>Wish to get some kind help to sort this problem.</p>
  
  <p>Appreciate any help in advance.</p>