file.py
__________________________________________________________________________________
import mmap
import re
from contextlib import closing
filename = '/home/copoka/lgek/admin_lgek'
pattern = re.compile(rb'(?sm)^CREATE TABLE .*?;', re.S)
with open(filename, 'r+b', 0) as f, \
closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as s:
MyList = re.findall(pattern, s) # return matched strings from the file
MyFile = open('/home/copoka/lgek/output.txt', 'w')
for x in MyList:
x = str(x).replace('\\n', '\n')
MyFile.write(x + '\n')
print (x)
MyFile.close()
__________________________________________________________________________
https://regex101.com/r/6cOCrn/2
Комментариев нет :
Отправить комментарий