forked from echlebek/nutes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_cleanup.go
63 lines (55 loc) · 889 Bytes
/
data_cleanup.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"flag"
"fmt"
"io"
"os"
)
func main() {
flag.Parse()
args := flag.Args()
if len(args) != 2 {
fmt.Println("usage: ./data_cleanup input.txt output.csv")
os.Exit(1)
}
inFile, err := os.Open(args[0])
defer inFile.Close()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
rd := bufio.NewReader(inFile)
outFile, err := os.Create(args[1])
defer outFile.Close()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
wr := bufio.NewWriter(outFile)
var r, lastR rune
for err == nil {
r, _, err = rd.ReadRune()
if err != nil {
break
}
switch r {
case '"':
switch lastR {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
wr.WriteString(" inch")
}
case '~':
case '^':
wr.WriteByte('\t')
default:
wr.WriteRune(r)
}
lastR = r
}
if err != io.EOF {
fmt.Println(err)
os.Exit(1)
}
wr.Flush()
}