-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (40 loc) · 857 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
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
if len(os.Args) < 2 {
os.Stderr.WriteString("Enter file name as argument\n")
os.Exit(1)
}
filename := os.Args[1]
readFile, err := os.Open(filename)
if err != nil {
os.Stderr.WriteString("Err opening file:" + filename + "\n")
os.Exit(1)
}
defer readFile.Close()
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
line := fileScanner.Text()
arr := strings.Split(line, ",")
if len(arr) != 2 {
os.Stderr.WriteString("Err line does not match signature:" + line + "\n")
os.Exit(1)
}
tag := arr[0]
count, err := strconv.Atoi(arr[1])
if err != nil {
os.Stderr.WriteString("Err CSV col-2 NaN:" + line + "\n")
os.Exit(1)
}
for i := 0; i < count; i++ {
fmt.Println(tag)
}
}
}