tred_extract_EDED_new
# -*- coding:utf-8 -*-
import re '''
适应新版本
''' year='17a'#用户自定义
ss='./data/'#根目录
filename = ss+'EDED%s.txt'%year#输入文件名 def tred_nonote(): p1 = r"^(?:\s{5}|X\s{4}|\W\s{4})(\d\d\d\d)\s\s[A-Z].+\]$"#匹配1001
p2 = r"^(?:\s{5}|X\s{4}|\W\s{4})\d\d\d\d\s\s([A-Z].+)\s+\[[A-Z]\]$"
p3 = r"^(?:\s{5}|X\s{4}|\W\s{4})\d\d\d\d\s\s[A-Z].+\s+\[([A-Z])\]$"
p4 = r"^\s{5}Desc:\s(.+\w\w\.)\n" p5 = r"^\s{5}Desc:\s(.+[^\.]|.+\.g\.)\n"#非以.结尾的Desc
p6 = r"^\s{11}(.+\.)\n"#非以.结尾的Desc的第二行
p7 = r"^\s{5}Repr:\s(.+)\n"#Repr pattern1 = re.compile(p1)
pattern2 = re.compile(p2)
pattern3 = re.compile(p3)
pattern4 = re.compile(p4)
pattern5 = re.compile(p5)
pattern6 = re.compile(p6)
pattern7 = re.compile(p7) fr = open(filename)
temp = ();
flag = 0
for line in fr.readlines():
matcher1 = re.findall(pattern1,line)
matcher2 = re.findall(pattern2,line)
matcher3 = re.findall(pattern3,line)
matcher4 = re.findall(pattern4,line)
matcher5 = re.findall(pattern5,line)
matcher6 = re.findall(pattern6,line)
matcher7 = re.findall(pattern7,line) w2 = open(ss+'tred_nonote%s.txt'%year,'a')#a代表追加 w代表重写
if matcher1:
flag = 1
w2.write("\n")
for j in matcher1:
for k in j:
w2.write(k) if ((matcher2!=[])and(flag ==1)):
flag = 2 w2.write(",")
for j in matcher2:
for k in j:
w2.write(k)
if ((matcher3!=[])and(flag ==2)):
flag = 3
# w2.write(",")
for j in matcher3:
for k in j:
w2.write(k)
if ((matcher4!=[])and(flag ==3)):
flag = 4
w2.write(",\"")
for j in matcher4:
for k in j:
w2.write(k)
w2.write("\"")
if ((matcher5!=[])and(flag ==3 or 5)):
flag = 5
w2.write(",\"")
for j in matcher5:
for k in j:
w2.write(k)
if ((matcher6!=[])and(flag ==5)):
flag = 6
w2.write(" ")
for j in matcher6:
for k in j:
w2.write(k)
w2.write("\"")
if ((matcher7!=[])and(flag ==4 or 6)):
flag = 7
w2.write(",")
for j in matcher7:
for k in j:
w2.write(k) w2.close( ) def tred_note(): p1 = r"^(?:\s{5}|X\s{4}|\W\s{4})(\d\d\d\d)\s\s[A-Z].+\]$"#匹配1001
p2 = r"^\s{5}Note:\s\n"#Note
p3= r"^\s{11}([^ ].+)\n"#Note内容
p4= r"^(?:-|컴)+\n"
pattern1 = re.compile(p1)
pattern2 = re.compile(p2)
pattern3 = re.compile(p3)
pattern4 = re.compile(p4) fr = open(filename)
w2 = open(ss+'tred_note%s.txt'%year,'a')#a代表追加 w代表重写
# temp = ();
flag = 0
flag1=0
for line in fr.readlines():
matcher1 = re.findall(pattern1,line)
matcher2 = re.findall(pattern2,line)
matcher3 = re.findall(pattern3,line)
matcher4 = re.findall(pattern4,line) #print matcher if matcher1!=[]:
flag = 1
w2.write("\n")
# for j in matcher1: # w2.write(j) if ((matcher2!=[])and(flag == 1)):
flag = 2
flag1=1
# w2.write(",")
if flag1==1:
if ((matcher3!=[])and(flag ==2 or 3)):
flag = 3
w2.write(" ")
for j in matcher3: w2.write(j)
# w2.write(")
if ((matcher4!=[])and(flag == 3)):
flag=0
flag1=0
w2.write("\n")
w2.close( )
fr.close() def join(): f1= open(ss+'tred_note%s.txt'%year)
f2 =open(ss+'tred_nonote%s.txt'%year) list_note=[]
for line1 in f1:
# print(line1)
if line1.isspace():
list_note.append('')
else:
list_note.append(line1) f1.close() # print(list_note)
f2_w= open(ss+'tred%s.csv'%year,'a')
# for i in range(len(list_note)):
i=0
# f2_r = open(ss+'/new/%s_w.txt'%list_tag[i])
for line2 in f2: str11="%s,\"%s\"\n"%(line2.strip('\n'),list_note[i].strip('\n'))
i=i+1
# print(i)
# print(str11)
f2_w.write(str11) f2_w.close()
f2.close()
if __name__ == '__main__':
tred_nonote()
tred_note()
join()
tred_extract_EDED_new的更多相关文章
随机推荐
- WDA-BOPF业务对象处理框架
SAP中的BOPF(Business Object Processing Framework) 正文 希望简化你的业务应用开发过程?业务对象处理框架(Business Object Processin ...
- spring boot 测试类
import org.junit.Test;import org.junit.runner.RunWith;import org.slf4j.Logger;import org.slf4j.Logge ...
- L2tp协议简单解析
1.L2TP简介 L2TP(Layer 2 Tunneling Protocol,二层隧道协议)是VPDN(Virtual PrivateDial-up Network,虚拟私有拨号网)隧道协议的一种 ...
- 组队打代码 !!! ——Alpha项目冲刺
Alpha阶段 - 博客链接合集 队伍名称: 代码那些事儿 学号 姓名 211606320 刘佳 211606313 李佳 211606303 陈水莲 211606302 曾丽丽 211606338 ...
- js中对话框的使用
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Mysql update 索引
执行mysql update,或者delete的时候会遇到: You can't specify target table for update in FROM clause 相关的原因自不必说:下面 ...
- Structs配置文件 zg项目介绍
Structs配置文件 1.以系统代码为名称 例:
- Installation failed with message INSTALL_CANCELED_BY_USER.
Installation failed with message INSTALL_CANCELED_BY_USER. It is possible that this issue is resolve ...
- django1.8模板位置的设置setting.py
大多数django教程比较老,给出的template的设置方案为: 更改工程下的setting.py文件, TEMPLATE_DIRS = ( os.path.join( APP_DIR, ' ...
- XX-net 部署网络
https://github.com/XX-net/XX-Net/wiki/%E4%BD%BF%E7%94%A8Chrome%E6%B5%8F%E8%A7%88%E5%99%A8 主要步骤有三步:安装 ...