Skip to content

Instantly share code, notes, and snippets.

@hiagop
Created June 10, 2017 03:11
Show Gist options
  • Save hiagop/18ab8590c857b984bf865420a57825ce to your computer and use it in GitHub Desktop.
Save hiagop/18ab8590c857b984bf865420a57825ce to your computer and use it in GitHub Desktop.
Quick way to have a CSV into a more readable format.
package main
import (
"encoding/csv"
"fmt"
"os"
)
func main() {
fields := []string{/*insert field names here*/}
file, err := os.Open(os.Args[1])
defer file.Close()
if err != nil {
os.Exit(1)
}
data := csv.NewReader(file)
data.Comment = '#'
data.Comma = ','
entries, err := data.ReadAll()
if err != nil {
os.Exit(1)
}
for _, entry := range entries {
for i, field := range fields {
fmt.Printf("%s: %s\n", field, entry[i])
}
fmt.Println()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment