# -*- coding:utf-8 -*-
import re '''
适应新版本
''' year='17A'#用户自定义
ss='./data/'#根目录
filename = ss+'EDSD%s.txt'%year#输入文件名 def trsd_nonote(): p1 = r"^\s{4}(?:X|\W)\s{2}([A-Z]{3})\s\s.+\n"#TCC
p2 = r"\s{4}(?:X|\W)\s{2}[A-Z]{3}\s\s(.+)\n"
"""
Function: To specify information regarding the transport
such as mode of transport, means of transport,
its conveyance reference number and the
identification of the means of transport.
"""
p3 = r"^\s{7}Function:\s(.+\w\w\.)\n"
p4 = r"^\s{7}Function:\s(.+\.g\.|.+[^\.])\n"
# p4 = r"^\s{7}Function:\s(.+[\.g\.|[^\.]])\n"
p5 = r"^\s{17}(\w.+[^\.])\n"
p6 = r"^\s{17}(.+\.)\n" #Note
# p7 = r"^\s{7}Note:\s\n"#Note
# p8= r"^\s{12}([A-Z].+\.)\n"#Note内容只有1行
# p9 = r"^\s{12}(.+[^\.]|)\n"#Note内容只多行的非最后行
# p10 = r"^\s{12}(.+\.)\n"#Note内容只多行的最后行 pattern1 = re.compile(p1)
pattern2 = re.compile(p2)
pattern3 = re.compile(p3)
pattern4 = re.compile(p4)
pattern5 = re.compile(p5)
pattern6 = re.compile(p6)
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)
#print matcher
w2 = open(ss+'trsd_nonote%s.txt'%year,'a')#a代表追加 w代表重写
if matcher1:
flag = 1
w2.write("\n")
for j in matcher1:
# for k in j:
w2.write(j)
if ((matcher2!=[])and(flag ==1)):
flag = 2
w2.write(",")
for j in matcher2:
# for k in j:
w2.write(j)
if ((matcher3!=[])and(flag ==2)):
flag = 3
#防止有逗号,用双引号括起
w2.write(",\"")
for j in matcher3:
# for k in j:
w2.write(j)
w2.write("\"")
if ((matcher4!=[])and(flag ==2)):
flag = 4
w2.write(",\"")
for j in matcher4:
# for k in j:
w2.write(j)
if ((matcher5!=[])and(flag ==4 or 5)):
flag = 5
w2.write(" ")
for j in matcher5:
# for k in j:
w2.write(j)
# w2.write("\"")
if ((matcher6!=[])and(flag ==4 or flag==5)):
flag = 6
w2.write(" ")
for j in matcher6:
# for k in j:
w2.write(j)
w2.write("\"")
w2.close( ) def trsd_note(): p1 = r"^(?:\s{7}|X\s{6}|\W\s{6})([A-Z]{3})\s\s[A-Z].+$"#匹配1001
p2 = r"^\s{7}Note:\s\n"#Note
p3= r"^\s{12}([^ ].+)\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+'trsd_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+'trsd_note%s.txt'%year)
f2 =open(ss+'trsd_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+'trsd%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__':
trsd_nonote()
trsd_note()
join()

trsd_extract_EDSD_new的更多相关文章

随机推荐

  1. css兼容性记录

    *        , ie6,ie7可以识别: _和- ,  ie6可以识别: !important  ,表示高优先级,ie7及以上,firefox都支持,ie6认识带!important的样式属性, ...

  2. H5特性回顾

    canvas 绘画, video 媒介回放 audio元素 对本地离线存储的更好支持, 新的特殊内容 - 元素 比如 article,footer,header,nav,section, 新的表单控件 ...

  3. dstat 性能监测工具

    dstat 是一个可以取代vmstat,iostat,netstat和ifstat这些命令的多功能产品.dstat克服了这些命令的局限并增加了一些另外的功能,增加了监控项,也变得更灵活了.dstat可 ...

  4. 使用FIO测试磁盘iops

    我们如何衡量一个存储的性能呢?IOPS(Input/Output OperationsPer Second),即每秒进行读写(I/O)操作的次数是国际上通用的存储性能衡量标准,IOPS越高意味着在同一 ...

  5. Haskell语言学习笔记(54)Data.Set

    Data.Set Prelude> import Data.Set as Set Prelude Set> :set -XOverloadedLists Construction Prel ...

  6. 【Java】JVM(二)、Java垃圾收集算法

    一.标记-清除算法 算法主要分为两个步骤 1. 标记: 遍历所有的 GC Roots, 然后标记所有可达对象为存活对象 2. 清除: 遍历堆中所有对象,然后将没有标记的对象清除. 存在不足: 1. 效 ...

  7. linux下的计算器

    (1)bc bc在默认的情况下是个交互式的指令.在bc工作环境下,可以使用以下计算符号:+ 加法 - 减法 * 乘法 / 除法 ^ 指数 % 余数如: 3+4;5*2;5^2;18/4      &l ...

  8. 133克隆图 · Clone Graph

    [抄题]: 克隆一张无向图,图中的每个节点包含一个 label 和一个列表 neighbors. [思维问题]: [一句话思路]: 先BFS克隆点(一个点+扩展所有邻居),再克隆邻居(一个点+扩展所有 ...

  9. 在不用重做系统下,把硬盘IDE模式修改为AHCI模式

    Win10自2015年7月29日诞生以来已经3年多了,虽然截至到现在Win7用户使用者仍然比Win10用户多,但是Win10用户也在逐渐增加 所使用的硬件--硬盘   用户为了更好的体验,也逐步的从H ...

  10. oracle pl sql import export

    http://blog.163.com/magicc_love/blog/static/185853662201281013345829/