日期:2014-05-17  浏览次数:21016 次

asp文件操作攻关级问题.谁能实现这样的结果
一个log文件.格式如下:
2007-05-13   16:12:25   GET   /   用户1   60.10.19.3   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:12:32   GET   /   用户2   60.10.19.3   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:17:47   GET   /   用户1   60.10.19.3   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:17:58   GET   /   用户2   60.10.19.5   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:18:03   GET   /   用户3   60.10.19.6   HTTP/1.1   Mozilla/4.0+   -   401   259


要求根据   ip和用户名   来排除重复的行.
也就是分析得出,所有IP的登陆纪录.上面的第一行和第三行的IP和用户名重复,
所以只保留第一行,去掉了第三行.如下:

2007-05-13   16:12:25   GET   /   用户1   60.10.19.3   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:12:32   GET   /   用户2   60.10.19.3   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:17:58   GET   /   用户2   60.10.19.5   HTTP/1.1   Mozilla/4.0+   -   401   259
2007-05-13   16:18:03   GET   /   用户3   60.10.19.6   HTTP/1.1   Mozilla/4.0+   -   401   259


------解决方案--------------------
用数据库,把数据存储到数据库里,再用GROUP BY查询出来,以前做过一个IIS 日志转adPersistADTG格式的程序,就用Split([数据], " ")即可,参考一下

Public Function GetIISRecord(ByVal strPath)
Dim fso
Dim fp
Dim rs
Dim strData
Dim arr, ptr, i
Set fso = WScript.CreateObject( "Scripting.FileSystemObject ")
Set rs = WScript.CreateObject( "ADODB.RecordSet ")
Set fp = fso.OpenTextFile(strPath)
Do While Not fp.AtEndOfStream
strData = fp.ReadLine
If Left(strData, 1) = "# " Then
If Left(strData, 7) = "#Fields " And rs.state = adStateClosed Then
arr = Split(Trim(Mid(strData, 10)), " ")
For Each ptr In arr
rs.Fields.Append ptr, adVarChar, 255
Next
rs.Open
End If
Else
arr = Split(strData, " ")
If UBound(arr) = rs.Fields.Count - 1 Then
rs.AddNew
For i = 0 To UBound(arr)
rs(i) = Replace(arr(i), "+ ", " ")
Next
rs.Update
End If
End If
Loop
Set fso = Nothing
If rs.state = adStateOpen Then
rs.MoveFirst
Set GetIISRecord = rs
Else
Set GetIISRecord = Nothing
End If
Set rs = Nothing
End Function

Dim rs, tmp, i
Set rs = GetIISRecord( "C:\Windows\System32\LogFiles\W3SVC1\ex070514.log ")
If Not rs Is Nothing Then
Do While Not rs.EOF
tmp = " "
For i = 0 To rs.Fields.Count - 1
tmp = tmp & rs(i) & ", "
Next
WScript.Echo tmp
rs.MoveNext
Loop
rs.Close
End If
Set rs = Nothing