-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp_tabfile.go
More file actions
72 lines (65 loc) · 1.3 KB
/
comp_tabfile.go
File metadata and controls
72 lines (65 loc) · 1.3 KB
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
64
65
66
67
68
69
70
71
72
package comptbfile
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
func Compare(fname1, fname2 string, beginLine, endLine, cellNum int) {
f1, err := os.Open(fname1)
if err != nil {
fmt.Println(err.Error())
return
}
defer f1.Close()
f2, ef2 := os.Open(fname2)
if ef2 != nil {
panic(ef2)
}
defer f2.Close()
f3, ef3 := os.Create("result.txt")
if ef3 != nil {
panic(ef3)
}
defer f3.Close()
buf2 := bufio.NewReader(f2)
buf1 := bufio.NewReader(f1)
buf3 := bufio.NewWriter(f3)
lineNum := 1
// begin := 1826
// end := 2745
for {
line1, err1 := buf1.ReadString('\n')
if err1 != nil && err1 == io.EOF {
break
}
line2, err2 := buf2.ReadString('\n')
if err2 != nil && err2 == io.EOF {
break
}
if lineNum >= beginLine && lineNum <= endLine {
l2 := strings.Split(line2, "\t")
l1 := strings.Split(line1, "\t")
if lineNum == beginLine {
_, err3 := buf3.WriteString(l1[0] + "\t" + l2[0] + "\r\n")
if err3 != nil {
panic(err3)
}
}
//fmt.Println(l1[35], "=", l2[35])
_, err3 := buf3.WriteString(l1[cellNum] + "====" + l2[cellNum] + "\r\n")
if err3 != nil {
panic(err3)
}
if lineNum == endLine {
_, err3 := buf3.WriteString(l1[0] + "\t" + l2[0] + "\r\n")
if err3 != nil {
panic(err3)
}
buf3.Flush()
}
}
lineNum++
}
}