# -*- coding:utf-8 -*-
import re year="17A"
ss='./data/'
filename = ss+'EDCD%s.txt'%year '''
适应新版本
''' p1 = r"^\s{4}(?:X|\W)\s{2}(C\d\d\d)\s.+\n"
p2 = r"^(\d\d\d)\s{4}\d{4}\s{2}.+[CM]\s+(?:.*\.\.\d+|.*)\n"#C n3
p3 = r"^\d\d\d\s{4}(\d{4})\s{2}.+[CM]\s+(?:.*\.\.\d+|.*)\n"
p4 = r"^\d\d\d\s{4}\d{4}\s{2}.+([CM])\s+(?:.*\.\.\d+|.*)\n"
p5 = r"^\d\d\d\s{4}\d{4}\s{2}.+[CM]\s+((?:.*\.\.\d+|.*))\n" p6 = r"^(\d\d\d)\s{4}\d{4}\s{2}.+[^\d]$\n"
p7 = r"^\d\d\d\s{4}(\d{4})\s{2}.+[^\d]$\n"
p8 = r"^\s{13}.+([CM])\s+(?:.*\.\.\d+|.*)\n"
p9 = r"^\s{13}.+[CM]\s+((?:.*\.\.\d+|.*))\n"
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)
pattern8 = re.compile(p8)
pattern9 = re.compile(p9)
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)
matcher8 = re.findall(pattern8,line)
matcher9 = re.findall(pattern9,line)
#print matcher
w2 = open(ss+'b3_%s.csv'%year,'a')#a代表追加 w代表重写
if matcher1:
flag = 1
for j in matcher1:
temp = j
if ((matcher2!=[])and(flag ==1 or 5 or 9)):
flag = 2
w2.write("\n"+temp+",")
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) if ((matcher5!=[])and(flag ==4)):
flag = 5
w2.write(",")
for j in matcher5:
for k in j:
w2.write(k) if ((matcher6!=[])and(flag ==1 or 5 or 9)):
flag = 6
w2.write("\n"+temp+",")
for j in matcher6:
for k in j:
w2.write(k)
if ((matcher7!=[])and(flag ==6)):
flag = 7
w2.write(",")
for j in matcher7:
for k in j:
w2.write(k)
if ((matcher8!=[])and(flag ==7)):
flag = 8
w2.write(",")
for j in matcher8:
for k in j:
w2.write(k) if ((matcher9!=[])and(flag ==8)):
flag = 9
w2.write(",")
for j in matcher9:
for k in j:
w2.write(k)
w2.close( )

b3_trcd_EDCD_new的更多相关文章

随机推荐

  1. neo4j 学习-1

    Neo4j 子句 ```MATCH (:Person { name: 'an' })-[r]->(:Persion) RETURN type(r) // 返回关系的类型 如:r 就是 'KNOW ...

  2. ==、is

    ==.is 总结 is 是比较两个引用是否指向了同一个对象(引用比较). == 是比较两个对象的值是否相等(值比较).

  3. express + mongodb 搭建一个简易网站 (三)

    express + mongodb 搭建一个简易网站 (三) 前面已经实现了基本的网站功能,现在我们就开始开搞一个完整的网站,现在整个网站的UI就是下面的这个样子. 我们网站的样子就照着这个来吧. 1 ...

  4. Linux Shell中有三种引号的用法

    Linux Shell中有三种引号,分别为双引号(" ").单引号(' ')以及反引号(` `). 其中双引号对字符串中出现的$.''.`和\进行替换:单引号不进行替换,将字符串中 ...

  5. SearchEngine Note

    [SearchEngine Note] 1.查全率. 2.查准率. 3.查全率与查准率的关系. 4.四大系统. 5.权威性网页反向链接多.网页的平均出席为25.7,即平均每一个网页含有25.7个指向其 ...

  6. CentOS 6.3安装配置supervisor进程管理工具

    1. Supervisor是一个C/S系统,它可以在类unix操作系统让用户来监视和控制后台服务进程的数量,一个很重要的功能就是监控服务器的主要后台进程,并在出现问题是自动重启. 2. 根据服务器上的 ...

  7. 让IE浏览器支持CSS3表现

    http://www.zhangxinxu.com/wordpress/2010/04/%e8%ae%a9ie6ie7ie8%e6%b5%8f%e8%a7%88%e5%99%a8%e6%94%af%e ...

  8. JPA报错, java.lang.NullPointerException

    java.lang.NullPointerException 我觉得这应该是一个很常见的错误, 数据库没取到数据嘛, 很正常, JPA没取到数据就是会抛出空指针异常, 但是就是这么简单的一个错误也让我 ...

  9. Majority Element(ARRAY-BINARY SEARCH)

    QUESTION Given an array of size n, find the majority element. The majority element is the element th ...

  10. 关于jni调用报UnsatisfiedLinkError的可能

    一.说明 最近在做一个项目,需要使用java去调本地动态连接库,之前做测试的时候直接用pojo进行测试,是能够正常调用的.后面项目需要将接口封装为REST api,所以在spring boot上面开发 ...