-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge-files
executable file
·64 lines (52 loc) · 1.46 KB
/
merge-files
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
#!/usr/bin/env python
import signal
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
import sys
from lib_alu_detect import *
#
# main
#
if len(sys.argv) != 3:
print >> sys.stderr, "usage: %s count1:<file1> count2:<file2>" % (sys.argv[0])
sys.exit(1)
if len(sys.argv[1].split(":")) < 2:
print >> sys.stderr, "invalid count:<file> specification (%s)" % sys.argv[1]
sys.exit(1)
if len(sys.argv[2].split(":")) < 2:
print >> sys.stderr, "invalid count:<file> specification (%s)" % sys.argv[2]
sys.exit(1)
count = []
file = []
count.append(int(sys.argv[1].split(":")[0]))
file.append(sys.argv[1].split(":")[1])
count.append(int(sys.argv[2].split(":")[0]))
file.append(sys.argv[2].split(":")[1])
if count[0] <= 0:
print >> sys.stderr, "error: count1 must be positive (%d)" % count[0]
sys.exit(1)
if count[1] <= 0:
print >> sys.stderr, "error: count2 must be positive (%d)" % count[1]
sys.exit(1)
#print >> sys.stderr, "using count1:%d file1:%s count2:%d file2:%s" % (count[0], file[0], count[1], file[1])
fd = []
fd.append(gzopen(file[0]))
fd.append(gzopen(file[1]))
buff = []
buff.append([None] * count[0])
buff.append([None] * count[1])
k = 0
while True:
for i in range(count[k]):
buff[k][i] = fd[k].readline()
if len(buff[k][i]) == 0:
break
if len(buff[k][i]) == 0:
break
if k == 1:
for i in range(count[0]):
print buff[0][i],
for i in range(count[1]):
print buff[1][i],
k = 1 - k
gzclose(fd[0])
gzclose(fd[1])