title: Reading text file and printing the vowel count
body: <p>I am trying to print vowel count from a text file. I am not getting the expected count. I can do this using a regular approach of just counting the character count using strings.Count(). But I want to use concurrency to see how it works. This is the link to text file -&gt; &quot;https://www.gutenberg.org/cache/epub/2600/pg2600.txt&quot;</p>
  <p>File size -&gt; 3.36 MB</p>
  <p>Below is my code.</p>
  <p>Any help is appreciated.</p>
  <p>Result I am getting using below code:</p>
  <p>A -  145310
  E -  188280
  I -  116195
  O -  131900
  U -  47560</p>
  <p>Expected result :</p>
  <p>A -  202712
  E -  313609
  I -  172232
  O -  190103
  U -  64401</p>
  <pre><code>package main
  
  import (
      &quot;bufio&quot;
      &quot;fmt&quot;
      &quot;io&quot;
      &quot;os&quot;
      &quot;strings&quot;
      &quot;sync&quot;
  )
  
  const mb = 1024 * 1024
  
  func main() {
  
      aCount, eCount, iCount, oCount, uCount := 0, 0, 0, 0, 0
  
      wg := &amp;sync.WaitGroup{}
  
      channel := make(chan (string))
  
      done := make(chan (bool), 1)
  
      go func() {
          for s := range channel {
  
              if strings.Contains(strings.ToUpper(s), &quot;A&quot;) {
                  aCount++
              }
              if strings.Contains(strings.ToUpper(s), &quot;E&quot;) {
                  eCount++
              }
              if strings.Contains(strings.ToUpper(s), &quot;I&quot;) {
                  iCount++
              }
              if strings.Contains(strings.ToUpper(s), &quot;O&quot;) {
                  oCount++
              }
              if strings.Contains(strings.ToUpper(s), &quot;U&quot;) {
                  uCount++
              }
          }
  
          done &lt;- true
      }()
  
      var current int64
  
      var limit int64 = 0.5 * mb
  
      for i := 0; i &lt; 5; i++ {
          wg.Add(1)
          go func() {
              read(current, limit, &quot;interview.txt&quot;, channel)
              fmt.Printf(&quot;%d thread has been completed&quot;, i)
              wg.Done()
          }()
  
          current += limit + 1
      }
  
      // Wait for all go routines to complete.
      wg.Wait()
      close(channel)
  
      &lt;-done
      close(done)
  
      fmt.Println(&quot;A - &quot;, aCount)
      fmt.Println(&quot;E - &quot;, eCount)
      fmt.Println(&quot;I - &quot;, iCount)
      fmt.Println(&quot;O - &quot;, oCount)
      fmt.Println(&quot;U - &quot;, uCount)
  
  }
  
  func read(offset int64, limit int64, fileName string, channel chan (string)) {
      file, err := os.Open(fileName)
      defer file.Close()
  
      if err != nil {
          panic(err)
      }
  
      file.Seek(offset, 0)
      reader := bufio.NewReader(file)
  
      if offset != 0 {
          _, err = reader.ReadBytes(' ')
          if err == io.EOF {
              fmt.Println(&quot;EOF&quot;)
              return
          }
  
          if err != nil {
              panic(err)
          }
      }
  
      var cummulativeSize int64
      for {
          // Break if read size has exceed the chunk size.
          if cummulativeSize &gt; limit {
              break
          }
  
          b, err := reader.ReadBytes(' ')
  
          // Break if end of file is encountered.
          if err == io.EOF {
              break
          }
  
          if err != nil {
              panic(err)
          }
  
          cummulativeSize += int64(len(b))
          s := strings.TrimSpace(string(b))
          if s != &quot;&quot; {
              channel &lt;- s
          }
      }
  }
  </code></pre>