亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5153 | 回復(fù): 7
打印 上一主題 下一主題

分割日志 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2013-09-02 15:42 |只看該作者 |倒序?yàn)g覽
1378107072.936      0 10.10.52.4 TCP_MEM_HIT  200 67716 GET http://www.iche.com/ - NONE  text/html
1378107077.007      0 10.10.52.4 TCP_MEM_HIT  200 593 GET http://www.a.com/ - NONE  text/html
1378107176.062     36 10.10.52.4 TCP_MISS  504 1579 GET http://www.b.com/ - FIRST_UP_PARENT  text/html

童鞋們,有上面這樣格式的一個(gè)日志,其中包含多種url,我想按照url分割日志,將同一個(gè)url的日志放在一起,并且將名字命名為分割后日志中url的名字

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2013-09-02 18:48 |只看該作者
回復(fù) 1# p8712351
  1. import re

  2. result = {}

  3. with open("t.txt", "r") as fdr:
  4.     for line in fdr.readlines():
  5.         urllist = line.rstrip().split(" ")
  6.         for url in urllist:
  7.             if re.match("^http", url):
  8.                 key = url.split("www.")[-1].split(".com")[0]
  9.                 if not result.has_key(key):
  10.                     result[key] = []
  11.                 result[key].append(line.rstrip())

  12. for name, content in result.items():
  13.     with open(name + ".out", "w+") as fdw:
  14.         for line in content:
  15.             fdw.write(line + "\n")
復(fù)制代碼

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2013-09-02 20:44 |只看該作者
本帖最后由 conn2011 于 2013-09-02 20:46 編輯

import re
for row in open(fn,"rb").readlines():
    try:
        open(re.search(r"http://(.+?)/",row).group(1),"w+").write(row)
    except:
        open("nourl.txt","w+").write(row)

論壇徽章:
1
操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-06-12 06:20:00
4 [報(bào)告]
發(fā)表于 2013-09-02 22:00 |只看該作者
readlines(): 這是讀出所有行吧,對于日志文件不太合適 

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2013-09-03 09:44 |只看該作者
回復(fù) 3# conn2011

這個(gè)不錯(cuò),夠簡潔!
   

論壇徽章:
5
丑牛
日期:2014-01-21 08:26:26卯兔
日期:2014-03-11 06:37:43天秤座
日期:2014-03-25 08:52:52寅虎
日期:2014-04-19 11:39:48午馬
日期:2014-08-06 03:56:58
6 [報(bào)告]
發(fā)表于 2013-09-03 13:29 |只看該作者
不錯(cuò) 3樓

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2013-09-08 15:50 |只看該作者
謝謝各位,我參考了1樓的了,之后忘記感謝各位了,抱歉

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2013-09-11 20:58 |只看該作者
#!/usr/local/bin/python
#-*- encoding:utf8 -*-
#author:sageskr
import re,time
input_log = open("/home/work/python/temp/log",'r')
input_log.seek(0,0)
while True:
    line = input_log.readline()
    if not line:
        time.sleep(1)
    else:
        regex_url = re.compile(r"http://([^/]+)")
        rt = regex_url.search(line).group(1)
        out_log = open('/home/work/python/temp/%s_log' %(rt),'a')
        out_log.write(line)
        #print >> out_log,line
        out_log.flush()
        out_log.close()


我這個(gè)可以實(shí)時(shí)的采集日志,并匯總輸出。希望不吝賜教
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP