43 lignes
1006 B
Go
43 lignes
1006 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/csv"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
var file = flag.String("file", "", "File to import")
|
|
var columnStart = flag.Int("columnStart", -1, "Column number with a start Datetime")
|
|
var columnEnd = flag.Int("columnEnd", -1, "Column number with a end Datetime")
|
|
var descriptiveColumn = flag.Int("columnDescription", -1, "Column number with a descriptive name or similar")
|
|
flag.Parse()
|
|
|
|
if _, err := os.Stat(*file); os.IsNotExist(err) || *columnStart == -1 || *columnEnd == -1 || *descriptiveColumn == -1 {
|
|
flag.Usage()
|
|
return
|
|
}
|
|
|
|
fmt.Println("Scanning file " + *file + "...")
|
|
readCsvFile(*file, *columnStart, *columnEnd, *descriptiveColumn)
|
|
}
|
|
|
|
func readCsvFile(csvFile string, columnStart int, columnEnd int, descriptiveColumn int) {
|
|
f, _ := os.Open(csvFile)
|
|
r := csv.NewReader(bufio.NewReader(f))
|
|
|
|
for {
|
|
record, err := r.Read()
|
|
if err == io.EOF {
|
|
break
|
|
}
|
|
|
|
for value := range record {
|
|
fmt.Printf(" %v\n", record[value])
|
|
}
|
|
}
|
|
}
|