免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2478 | 回复: 1
打印 上一主题 下一主题

如何分隔以下的字符串 [复制链接]

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015元宵节徽章
日期:2015-03-06 15:51:33
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-09-18 16:16 |只看该作者 |倒序浏览
有一个文件内容如下:
"备份操作已取消。","8","2",,"2","0","0","4611686018427387904","5","Microsoft-Windows-Backup","1db28f2e-8f80-4027-8c5a-a11f7f10f62d","Microsoft-Windows-Backup","3244","1880","7FwaibaoAD.game.waibao.com","S-1-5-18","2015/9/15 19:50:32",,,"microsoft-windows-backup","System.Int32[]","System.Diagnostics.Eventing.Reader.EventBookmark","错误","信息",,"System.Collections.ObjectModel.ReadOnlyCollection`1[System.String]","System.Collections.Generic.List`1[System.Diagnostics.Eventing.Reader.EventProperty]"

"备份操作已启动。","1","1",,"4","0","1","4611686018427387904","4","Microsoft-Windows-Backup","1db28f2e-8f80-4027-8c5a-a11f7f10f62d","Microsoft-Windows-Backup","3244","1880","7FwaibaoAD.game.waibao.com","S-1-5-18","2015/9/15 19:49:36",,,"microsoft-windows-backup","System.Int32[]","System.Diagnostics.Eventing.Reader.EventBookmark","信息","启动",,"System.Collections.ObjectModel.ReadOnlyCollection`1[System.String]","System.Collections.Generic.List`1[System.Diagnostics.Eventing.Reader.EventProperty]"

"备份操作已完成。","14","2",,"4","0","2","4611686018427387904","3","Microsoft-Windows-Backup","1db28f2e-8f80-4027-8c5a-a11f7f10f62d","Microsoft-Windows-Backup","3244","3144","7FwaibaoAD.game.waibao.com","S-1-5-18","2015/9/15 19:47:06",,,"microsoft-windows-backup","System.Int32[]","System.Diagnostics.Eventing.Reader.EventBookmark","信息","停止",,"System.Collections.ObjectModel.ReadOnlyCollection`1[System.String]","System.Collections.Generic.List`1[System.Diagnostics.Eventing.Reader.EventProperty]"

通过以下读取文件
file_info=open(file_path)
    for file_line in file_info:

如果想将文件内容分隔为以下的格式,应该如何写?

备份操作已启动。 1 1 4 0 1 4611686018427387904......

因为需要将文件内容按字段提取写入数据库的,是否可以先删除"号,再按,号来进行分隔?

论坛徽章:
4
白羊座
日期:2013-11-05 10:26:09冥斗士
日期:2015-11-17 14:19:55白银圣斗士
日期:2015-11-17 15:13:0815-16赛季CBA联赛之新疆
日期:2016-04-01 09:10:58
2 [报告]
发表于 2015-09-18 16:33 |只看该作者
应该不用这么麻烦,假定log信息在"sample.log"文件里面,代码如下:
  1. with open("Sample.log", "r") as logHandle:
  2.     inStream = csv.reader(logHandle)
  3.     for line in inStream:
  4.         record = " ".join(line)
  5.         print record
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP