-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_read.py
executable file
·62 lines (58 loc) · 1.53 KB
/
file_read.py
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
'''
file_location = '/home/metal-machine/Desktop/nohup.out'
import re
import time
import numpy as np
a=np.array([])
with open(file_location,'r') as f:
m = re.findall(r'tt\d\d\d\d\d\d\d',f.read())
np_array = np.append(a,m)
print np_array
print np_array.size
print 'unique'
print np.unique(np_array)
print np.unique(np_array).size
np.save('/home/metal-machine/Desktop/nohup.npy',np.unique(np_array))
'''
#file_location = '/home/arshpreetsingh/nohup.out'
file_location = '/home/metal-machine/Desktop/nohup.out'
def read_in_chunks(file_object):
"""Lazy function (generator) to read a file piece by piece.
Default chunk size: 1k."""
while True:
data = file_object.read()
if not data:
break
yield data
import numpy as np
import re
a=np.array([])
my_regex=re.compile(r'tt\d\d\d\d\d\d\d')
f = open(file_location)
def iterate_regex():
for piece in read_in_chunks(f):
yield re.findall(my_regex,piece)
for i in iterate_regex():
np_array = np.append(a,i)
print np_array
print np_array.size
print 'unique'
print np.unique(np_array)
print np.unique(np_array).size
#print m
'''
import re
import time
import numpy as np
a=np.array([])
my_regex = re.compile(r'tt\d\d\d\d\d\d\d')
with open(file_location,'r') as f:
m = re.findall(my_regex,f.read())
np_array = np.append(a,m)
print np_array
print np_array.size
print 'unique'
print np.unique(np_array)
print np.unique(np_array).size
#np.save('/home/arshpreetsingh/nohup.npy',np.unique(np_array))
'''