Last active
August 29, 2015 13:56
-
-
Save johnwesonga/9133337 to your computer and use it in GitHub Desktop.
Read a CSV file, skipping the headers
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" | |
_ "io" | |
"os" | |
) | |
func checkCsv() { | |
file, err := os.Open("names.txt") | |
if err != nil { | |
fmt.Println("Error:", err) | |
return | |
} | |
defer file.Close() | |
reader := csv.NewReader(file) | |
records, err := reader.ReadAll() | |
// skip the header row | |
for _, r := range records[1:] { | |
fmt.Println("account ", r[0]) // record has the type []string | |
} | |
} | |
func main() { | |
checkCsv() | |
} |
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
name, age | |
john, 21 | |
peter, 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment