title: Scanning words in a text file by Golang
body: <p>I want to split a text file(file.txt) into two separate equal size texts files such as file1.txt and file2.txt. My strategy in the split is to scan words and count them and then write the first half of the words to file1.txt and the rest to file2.txt 
  This is the code:</p>
  
  <pre><code>package main
  import (
      "bufio"
      "fmt"
      "log"
      "os"
  )
  func main() {
      WordbyWordScan()
  }
  func WordbyWordScan() {
      file, err := os.Open("file.txt.txt")
      if err != nil {
          log.Fatal(err)
      }
      defer file.Close()
      scanner := bufio.NewScanner(file)
      scanner.Split(bufio.ScanWords)
      count := 0
      for scanner.Scan() {
          fmt.Println(scanner.Text())
          count++
      }
      if err := scanner.Err(); err != nil {
          log.Fatal(err)
      }
      fmt.Printf("%d\n", count)
  }
  </code></pre>
  
  <p><a href="https://godoc.org/bufio#example-Scanner--Words" rel="nofollow noreferrer">https://godoc.org/bufio#example-Scanner--Words</a></p>
  
  <p>As far as I can guess scanner.Scan() returns a boolean. After counting the number of words, How I can implement such a code in Golang that states write the first half of words to file1.txt and the rest in file2.txt?   </p>