title: How to read a file starting from a specific line number using Scanner?
body: <p>I am new to Go and I am trying to write a simple script that reads a file line by line. I also want to save the progress (i.e. the last line number that was read) on the filesystem somewhere so that if the same file was given as the input to the script again, it starts reading the file from the line where it left off. Following is what I have started off with.</p>
  
  <pre><code>package main
  
  // Package Imports
  import (
      "bufio"
      "flag"
      "fmt"
      "log"
      "os"
  )
  
  // Variable Declaration
  var (
      ConfigFile = flag.String("configfile", "../config.json", "Path to json configuration file.")
  )
  
  // The main function that reads the file and parses the log entries
  func main() {
      flag.Parse()
      settings := NewConfig(*ConfigFile)
  
      inputFile, err := os.Open(settings.Source)
      if err != nil {
          log.Fatal(err)
      }
      defer inputFile.Close()
  
      scanner := bufio.NewScanner(inputFile)
      for scanner.Scan() {
          fmt.Println(scanner.Text())
      }
  
      if err := scanner.Err(); err != nil {
          log.Fatal(err)
      }
  }
  
  // Saves the current progress
  func SaveProgress() {
  
  }
  
  // Get the line count from the progress to make sure
  func GetCounter() {
  
  }
  </code></pre>
  
  <p>I could not find any methods that deals with line numbers in the scanner package. I know I can declare an integer say <code>counter := 0</code> and increment it each time a line is read like <code>counter++</code>. But the next time how do I tell the scanner to start from a specific line? So for example if I read till line <code>30</code> the next time I run the script with the same input file, how can I make scanner to start reading from line <code>31</code>?</p>
  
  <h3>Update</h3>
  
  <p>One solution I can think of here is to use the counter as I stated above and use an if condition like the following.</p>
  
  <pre><code>    scanner := bufio.NewScanner(inputFile)
      for scanner.Scan() {
          if counter &gt; progress {
              fmt.Println(scanner.Text())
          }
      }
  </code></pre>
  
  <p>I am pretty sure something like this would work, but it is still going to loop over the lines that we have already read. Please suggest a better way.</p>