Created
June 10, 2017 03:11
-
-
Save hiagop/18ab8590c857b984bf865420a57825ce to your computer and use it in GitHub Desktop.
Quick way to have a CSV into a more readable format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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