-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
49 lines (45 loc) · 890 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"bufio"
"log"
"os"
"strings"
)
func main() {
rsv, _ := os.Open("example.rsv")
defer rsv.Close()
scanner := bufio.NewScanner(rsv)
scanner.Split(bufio.ScanLines)
var headers []string
headersRead := false
var row []string
for scanner.Scan() {
value := ""
if false == headersRead {
text := scanner.Text()
parts := strings.Split(text, ",")
headers = append(headers, parts[0])
if len(parts) == 1 {
continue
}
headersRead = true
value = parts[1]
} else {
value = scanner.Text()
}
parts := strings.Split(value, ",")
row = append(row, parts[0])
if len(parts) == 1 {
continue
}
print(headers, row)
row = []string{parts[1]}
}
print(headers, row)
}
func print(headers []string, row []string) {
log.Println("--------------")
for index, header := range headers {
log.Printf("%s: %s", header, row[index])
}
}