求助!紧急!如何读取文件,并对其中数据逐行累加

lcrainrock 2006-02-27 11:24:35
小弟是初学者,现在公司交给我一个难题,需要从日志文件中得到各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
由于尽快需要解决难题,重复发贴还请大家原谅!

...全文
62 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lcrainrock 2006-02-27
  • 打赏
  • 举报
回复
楼上大虾的代码小弟调试过了,显示错误
错误类型:
Microsoft VBScript 运行时错误 (0x800A000D)
类型不匹配: '[string: "-, N, 04-1-31, 9:42:"]'
/tet.asp, 第 28 行


浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)

网页:
GET /tet.asp
希望各位大虾能给小弟给出的原代码做下修改,或指点小弟如何逐行对同一IP的流量进行累加,并输出
尚和空四 2006-02-27
  • 打赏
  • 举报
回复
<%
''********************************************************************************
''变量定义区
dim lngPageAmount
dim lngPageNo
dim lngPageCount
dim fin
dim f
dim filepath
dim lineCount
dim total
''*************************************************************************
lngPageAmount = 4
lngPageNo = cint(request("lngPageNo"))
if len(lngPageNo) = 0 or lngPageNo = 0 then
lngPageNo = 1
end if
''****************************************************************************
set fin = Server.CreateObject("Scripting.FileSystemObject") '先读取文件
filepath = Server.MapPath("../writeTxt/writeTxt.txt")
set f = fin.OpenTextFile(filepath)
lineCount = f.readline
total = int(mid(lineCount,7))
response.Write(total & "<hr>")
''***************************************************************
lngPageCount = int((total/lngPageAmount) + 0.99) '加0.99 不够一页的算做一页
response.Write(lngPageCount & "<hr>")
if lngPageNo > lngPageCount then
lngPageNo = 1
end if
dim i, j, k
dim line
''+++++++++++++++++++++++++++++++++++++++++++++++++++++
if not lngPageNo = 1 then '跳过前面几页的内容
for j = 1 to ((lngPageNo -1) * lngPageAmount)
f.SkipLine
if f.AtendofStream then exit for
next
end if
%>

2,100

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧