Skip to content

Instantly share code, notes, and snippets.

@ehazlett
Created April 18, 2014 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehazlett/11068998 to your computer and use it in GitHub Desktop.
Save ehazlett/11068998 to your computer and use it in GitHub Desktop.
Go: CSV parsing
package main
import (
"encoding/csv"
"flag"
"fmt"
"io"
"os"
)
var filename string
func init() {
flag.StringVar(&filename, "f", "", "CSV Filename")
}
func main() {
flag.Parse()
f, err := os.Open(filename)
if err != nil {
fmt.Printf("Unable to open %s: %s", filename, err)
return
}
r := csv.NewReader(f)
for {
line, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
fmt.Printf("Error reading line: %s", err)
continue
}
fmt.Println(line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment