1. # -*- coding:utf-8 -*-
  2. import re
  3.  
  4. year="17A"
  5. ss='./data/'
  6. filename = ss+'EDCD%s.txt'%year
  7.  
  8. '''
  9. 适应新版本
  10. '''
  11.  
  12. p1 = r"^\s{4}(?:X|\W)\s{2}(C\d\d\d)\s.+\n"
  13. p2 = r"^(\d\d\d)\s{4}\d{4}\s{2}.+[CM]\s+(?:.*\.\.\d+|.*)\n"#C n3
  14. p3 = r"^\d\d\d\s{4}(\d{4})\s{2}.+[CM]\s+(?:.*\.\.\d+|.*)\n"
  15. p4 = r"^\d\d\d\s{4}\d{4}\s{2}.+([CM])\s+(?:.*\.\.\d+|.*)\n"
  16. p5 = r"^\d\d\d\s{4}\d{4}\s{2}.+[CM]\s+((?:.*\.\.\d+|.*))\n"
  17.  
  18. p6 = r"^(\d\d\d)\s{4}\d{4}\s{2}.+[^\d]$\n"
  19. p7 = r"^\d\d\d\s{4}(\d{4})\s{2}.+[^\d]$\n"
  20. p8 = r"^\s{13}.+([CM])\s+(?:.*\.\.\d+|.*)\n"
  21. p9 = r"^\s{13}.+[CM]\s+((?:.*\.\.\d+|.*))\n"
  22. pattern1 = re.compile(p1)
  23. pattern2 = re.compile(p2)
  24. pattern3 = re.compile(p3)
  25. pattern4 = re.compile(p4)
  26. pattern5 = re.compile(p5)
  27.  
  28. pattern6 = re.compile(p6)
  29. pattern7 = re.compile(p7)
  30. pattern8 = re.compile(p8)
  31. pattern9 = re.compile(p9)
  32. fr = open(filename)
  33. temp = "";
  34. flag = 0
  35. for line in fr.readlines():
  36. matcher1 = re.findall(pattern1,line)
  37. matcher2 = re.findall(pattern2,line)
  38. matcher3 = re.findall(pattern3,line)
  39. matcher4 = re.findall(pattern4,line)
  40. matcher5 = re.findall(pattern5,line)
  41.  
  42. matcher6 = re.findall(pattern6,line)
  43. matcher7 = re.findall(pattern7,line)
  44. matcher8 = re.findall(pattern8,line)
  45. matcher9 = re.findall(pattern9,line)
  46. #print matcher
  47. w2 = open(ss+'b3_%s.csv'%year,'a')#a代表追加 w代表重写
  48. if matcher1:
  49. flag = 1
  50. for j in matcher1:
  51. temp = j
  52. if ((matcher2!=[])and(flag ==1 or 5 or 9)):
  53. flag = 2
  54. w2.write("\n"+temp+",")
  55. for j in matcher2:
  56. for k in j:
  57. w2.write(k)
  58.  
  59. if ((matcher3!=[])and(flag ==2)):
  60. flag = 3
  61. w2.write(",")
  62. for j in matcher3:
  63. for k in j:
  64. w2.write(k)
  65.  
  66. if ((matcher4!=[])and(flag ==3)):
  67. flag = 4
  68. w2.write(",")
  69. for j in matcher4:
  70. for k in j:
  71. w2.write(k)
  72.  
  73. if ((matcher5!=[])and(flag ==4)):
  74. flag = 5
  75. w2.write(",")
  76. for j in matcher5:
  77. for k in j:
  78. w2.write(k)
  79.  
  80. if ((matcher6!=[])and(flag ==1 or 5 or 9)):
  81. flag = 6
  82. w2.write("\n"+temp+",")
  83. for j in matcher6:
  84. for k in j:
  85. w2.write(k)
  86. if ((matcher7!=[])and(flag ==6)):
  87. flag = 7
  88. w2.write(",")
  89. for j in matcher7:
  90. for k in j:
  91. w2.write(k)
  92. if ((matcher8!=[])and(flag ==7)):
  93. flag = 8
  94. w2.write(",")
  95. for j in matcher8:
  96. for k in j:
  97. w2.write(k)
  98.  
  99. if ((matcher9!=[])and(flag ==8)):
  100. flag = 9
  101. w2.write(",")
  102. for j in matcher9:
  103. for k in j:
  104. w2.write(k)
  105. w2.close( )

b3_trcd_EDCD_new的更多相关文章

随机推荐

  1. mysql之MMM高可用方案简介

    MMM(Master-Master Replication Manager for MySQL) MySQL主主复制管理器,提供了MySQL主主复制配置的监控.故障转移和管理的一套可伸缩的脚本套件.在 ...

  2. GBDT 将子树结果当成lr输出

    http://scikit-learn.org/stable/auto_examples/ensemble/plot_feature_transformation.html#example-ensem ...

  3. spring boot 配置 freemarker

    1.springboot 中自带的页面渲染工具为thymeleaf 还有freemarker 这两种模板引擎 简单比较下两者不同, 1.1freemaker 优点 freemarker 不足:thym ...

  4. FP真验货客户的成品和半成品编码部分没有带尾续,导致FP规划错误 IN_SALES_ORDER数据不带CZ

    错误描述:真验货客户的成品和半成品编码部分没有带尾续,导致FP规划错误 IT角度: IN_SALES_ORDER数据不带CZ 现时前台页面数据: 现时后台数据: 一.跟进情况 1.执行SAP_SALE ...

  5. <script language = "javascript">, <script type = "text/javascript">和<script language = "application/javascript">(转)

          application/javascript是服务器端处理js文件的mime类型,text/javascript是浏览器处理js的mime类型,后者兼容性更好(虽然application/ ...

  6. POJ1950----DFS

    Dessert Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6193   Accepted: 2299 Descripti ...

  7. 第五章 二叉树(b)树的表示

  8. 在MyEclipse Tomcat可以运行但是在Tomcat 6.x上却不可以运行

  9. Python3 tuple 函数

    Python3 tuple 函数  Python3 内置函数 描述 tuple 函数将列表转换为元组.. 语法 以下是 tuple 的语法: tuple( seq ) 参数 seq -- 要转换为元组 ...

  10. Eclipse中的SVN操作

    --------------------siwuxie095                                     Eclipse 中的 SVN 操作         (一)发布项目 ...