求助!紧急!如何读取文件,并对其中数据逐行累加
小弟是初学者,现在公司交给我一个难题,需要从日志文件中得到各IP地址所对应的网络流量
其格式如下
-, -, -, N, 04-1-31, 21:13:36, 1, -, http://image2.sina.com.cn/
-, -, -, N, 04-1-31, 21:13:36, 1, -, http://image2.sina.com.cn/sms/sinarc/
-, -, -, N, 04-1-31, 21:13:36, 1, -, -, http://news.sina.com.cn/
10.140.79.158, cyats\zyxia, -, Y, 04-1-31, 21:13:36, 1, -, -, image2.sina.com.cn, -, 80, 1062, 8202, 8606,
10.140.79.158, cyats\zyxia, -, Y, 04-1-31, 21:13:37, 1, -, -, image2.sina.com.cn, -, 80, 516, 3921, 1477,
10.140.79.158, cyats\zyxia, -, Y, 04-1-31, 21:13:37, 1, -, -, image2.sina.com.cn, -, 80, 625, 905, 1743,
在IP标注行,字符80后面3组数字分别是该地址响应时间,发送字节和接收字节,需要统计同一IP的总流量,即发送字节和接受字节的总量。
小弟刚学编程不久,实在无能力编写以上程序希望各位大大能指点小弟如何编写程序,最好能给出源代码,小弟将不胜感激。
以为大虾给出一段源代码,小弟以调试成功
<%
Dim psPath,Fso,Fil,S,S1,sIP,sL1,sL2
'获取文件的绝对地址
psPath=Server.MapPath("test.txt")
'读取文件内容
Set Fso=Server.CreateObject("Scripting.FileSystemObject")
Set Fil=Fso.OpenTextFile(psPath)
S=Fil.ReadAll
'通过文本特征取得IP及流量值
if Instr(S,",")>0 then
S=split(s,vbcrlf)
for i=0 to ubound(S)
S1=split(S(i)&",",",")
if len(S1(0))>3 then
sIP=S1(0)
sL1=S1(12)
sL2=S1(13)
Response.write "IP="& sIP &" 发送字节=" & sL1 &" 接收字节=" & sL2 &"<br/>"
end if
Next
End if
set fil=nothing
set Fso=nothing
%>
但该代码不能只能对IP和流量进行输出,不能逐行对同一IP的流量进行累加,还希望各位大虾指点。具体输出情况可以查看小弟另一个贴子http://community.csdn.net/Expert/topic/4574/4574723.xml?temp=.1954615
由于尽快需要解决难题,重复发贴还请大家原谅!