某网友的一个问题,想用awk对一个文件进行处理,可是没有思路
Release SPA Problem owner
289 DROUTER cr_123 jiji
2810 DROUTER cr_1234 qiqi
289 EPAY cr_234 zhaon
289 DROUTER cr_12345 qiqi
结果 :
Release : 289
SPA: DROUTER
cr_123 jiji
cr_234 zhaon
SPA:EPAY
cr_12345 qiqi
Release: 2810
SPA:DROUTER
cr_1234 qiqi
下面的是我的python的代码
- #!/usr/bin/python
- FD = open("/root/data","r")
- R = {}
- firline = FD.readline()
- for line in FD.readlines():
- tmp=line.split()
- if tmp[0] in R:
- if tmp[1] in R[tmp[0]]:
- R[tmp[0]][tmp[1]][tmp[3]]=tmp[2]
- else :
- R[tmp[0]][tmp[1]]={}
- R[tmp[0]][tmp[1]][tmp[3]]=tmp[2]
- else:
- R[tmp[0]]={}
- R[tmp[0]][tmp[1]]={}
- R[tmp[0]][tmp[1]][tmp[3]]=tmp[2]
- for release in R.keys():
- print "Release: " + release
- for spa in R[release].keys():
- print "\tSPA: " + spa
- for own in R[release][spa].keys():
- print "\t\t" + R[release][spa][own] + "\t" + own
阅读(1789) | 评论(0) | 转发(0) |