# -*- coding:utf-8 -*-
import re ss="./data/"
year = '17A'
filename = ss+'EDSD%s.txt'%year '''
适应新版本 ''' p1 = r"^\s{4}(?:X|\W)\s{2}([A-Z]{3})\s\s.+\n"#TC
p2 = r"(^\d{3})\s{4}C\d{3}.+[CM]\s+\d\n"#
p3 = r"^\d{3}\s{4}(C\d{3}).+[CM]\s+\d\n"#C552
p4 = r"^\d{3}\s{4}C\d{3}.+([CM])\s+\d\n"#M
p5 = r"^\d{3}\s{4}C\d{3}.+[CM]\s+(\d)\n"#
p6= r"(^\d{3})\s{4}\d{4}.+[CM]\s{4}\d\s.*\.\.\d+\n|(^\d{3})\s{4}\w\d{3}\s.+[^\d]$\n"#单独的030
p7 =r"^\d{3}\s{4}(\d{4}).+[CM]\s{4}\d\s.*\.\.\d+\n|^\d{3}\s{4}(\w\d{3})\s.+[^\d]$\n"#单独的3286
p8 =r"^\d{3}\s{4}\d{4}.+([CM])\s{4}\d\s.*\.\.\d+\n|^\s{12}[A-Z].+([CM])\s{4}\d\s.*\.\.\d+\n"#单独的M
p9 =r"^\d{3}\s{4}\d{4}.+[CM]\s{4}(\d)\s.*\.\.\d+\n|^\s{12}[A-Z].+[CM]\s{4}(\d)\s.*\.\.\d+\n"#单独的1
p10 =r"^\d{3}\s{4}\d{4}.+[CM]\s{4}\d\s(.*\.\.\d+)\n|^\s{12}[A-Z].+[CM]\s{4}\d\s(.*\.\.\d+)\n"#单独的an..35 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)
pattern10 = re.compile(p10) 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)
matcher10 = re.findall(pattern10,line)
#print matcher
w2 = open(ss+'b2_%s.csv'%year,'a')#a代表追加 w代表重写
if (matcher1!=[]):
for g in matcher1:
flag = 1
temp = g
if ((matcher2!=[])and(flag ==1 or 2)):
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)
#复合的缺省为0000
w2.write(",0000")
if ((matcher4!=[])and(flag ==3)):
flag = 4
w2.write(",")
for j in matcher4:
for k in j:
w2.write(k)
#增加固定列year
w2.write(","+year)
if ((matcher5!=[])and(flag ==4)):
flag = 5
w2.write(",")
for j in matcher5:
for k in j:
w2.write(k)
w2.write(", ")
# print len(matcher6)
if(len(matcher6)==1 and matcher6!=[''] ): flag = 6
w2.write("\n"+temp+",")
for j in matcher6:
for k in j:
w2.write(k)
#单独的缺省为C000
w2.write(",C000")
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)
#增加固定列year
w2.write(","+year)
if ((matcher9!=[])and(flag ==8)):
flag = 9
w2.write(",")
for j in matcher9:
for k in j:
w2.write(k)
if ((matcher10!=[])and(flag ==9)):
flag = 10
w2.write(",")
for j in matcher10:
for k in j:
w2.write(k)
w2.close( ) """
特殊情况 """

b2_trsd_EDSD_new的更多相关文章

随机推荐

  1. from __future__ import division

    导入python未来支持的语言特征division(精确除法),当我们没有在程序中导入该特征时,"/"操作符执行的是截断除法(Truncating Division),当我们导入精 ...

  2. 第一个gulp程序

    说起来惭愧,一直用公司内部的工具,没有用这些红得发紫的东西.今天东抄西拼终于搞出第一个gulp应用.gulp是做什么的,好处在哪儿我不废话了.直入主题吧. 先在D盘下建立一个xxxx目录,然后打开控制 ...

  3. Spring Boot中启动HTTPS

    一,生成https 的证书 1,在相应的根目录下 keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize -keyst ...

  4. oracle与DB2

    1.体系结构,DB2的实例和数据库分开的做法,我个人还是比较喜欢的,因为实例可以创建多个,数据库的恢复直接恢复到实例下就可以了,相对ORACLE简单多了. 2.管理工具,DB2的管理工具做得太简陋了, ...

  5. Intellij IDEA 热部署处理

     1. 首先参考IDEA热部署同行经验分享:  Intellij IDEA 4种配置热部署的方法 2. IDEA 热部署实战: springboot项目: 不要引入热部署工具包spring-boot- ...

  6. jquery datatables api

    原文地址 学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/ ...

  7. MVC扩展HtmlHelper,加入RadioButtonList、CheckBoxList、DropdownList

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions ...

  8. Navicat Premium 12破解补丁

    Navicat Premium 12破解补丁是专门针对Navicat 12制作的一款破解工具,它可以帮助大家成功激活软件,激活后就可以免费使用软件所有功能了,小编亲测可用,有需要的可以下载试试. Na ...

  9. 用python做数值计算

    http://sebug.net/paper/books/scipydoc/scipy_intro.html http://www.cnblogs.com/weilq/p/3432817.html h ...

  10. resin-pro-4.0.53报错java.lang.Error: java.lang.ClassNotFoundException: com.caucho.loader.SystemClassLoader

    最初并未发现,笔者的系统环境变量JAVA_HOME变量设置错误 D:\develop\Java\x64\jdk1.8.0_144 #最初使用了阉割版的JDK 改成完整安装的JDK就可以 D:\deve ...