当前位置:网站首页>使用VBScript读取网络的日志数据进行处理
使用VBScript读取网络的日志数据进行处理
2022-06-11 21:49:00 【dawn】
在交换机数据被读取出来后,可以使用VBScript脚本来编写读取程序。
可以写入到Excel或者其他文件中,也可以写入到数据库中。
在前面的文件中使用VBScript将数据写到了数据库中。
这里完成写入Excel文件中,方便进行各种分析处理。
代码:
'文件操作
dim TxtFileName
dim FilePath
dim ExcelRowCount
dim ExcelColName
TxtFileName="日志文件"
FilePath="文件路径"
Function RemoveSpace(StrSrc)
Dim re
Set re = New RegExp
're = CreateObject("vbscript.regexp")
re.Pattern = "\s+"
re.Global = True
RemoveSpace = re.Replace(StrSrc, ",")
End Function
'创建文件对象
set fso=CreateObject("Scripting.FileSystemObject")
'打开日志文件
set fo=fso.OpenTextFile(FilePath & "\" & TxtFileName,1,false)
'创建excel对象
Set excelObj = CreateObject("Excel.Application")
excelObj.visible=false
'打开excel文件
Set ExcelBook= excelObj.Workbooks.Open(FilePath & "\" & "Excel文件名")
'定位excel的工作簿
set ExcelSheet=excelObj.Worksheets("Sheet1")
'=============
'set ExcelBook=excelObj.workbooks.add
'set ExcelSheet=ExcelBook.worksheets(1)
ExcelRowCount=0
'按行读取数据文件
do while fo.AtEndOfStream <> true
'读取一行数据
line=fo.ReadLine
'去掉最后的空格
line=trim(line)
'将空格转换为,
line=RemoveSpace(line)
'提取数据到数组
Paras=Split(line,",")
if inStr(Paras(0),"XXX.YYY")=1 then
ExcelRowCount=ExcelRowCount+1
for i=0 to ubound(Paras)
ExcelColName= chr(65+i)
ExcelSheet.Range(ExcelColName & ExcelRowCount).Value=Paras(i)
'ExcelSheet.cells(i+1,ExcelRowCount).value=Paras(i)
'WScript.Echo Paras(i)
next
'WScript.Echo Chr(13)
end if
loop
excelObj.Workbooks(1).Save
fo.close
set fso=Nothing
ExcelBook.Close
excelObj.Quit
Set ExcelBook = Nothing
Set excelObj = Nothing
有了上面的处理,后面可以做的事情就比较多了。
边栏推荐
- Popular science | what are the types of NFT (Part 1)
- In the future, cloud expansion technology is expected to be selected as a specialized, special and new enterprise in Shanghai
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.4
- crontab中定时执行shell脚本
- 类与对象(3)
- 【学术相关】申请审核制下,到双一流大学读博的难度有多大?
- 69. x的平方根
- 判断大小端存储两种办法
- R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest
- C language to achieve eight sorts (2)
猜你喜欢
随机推荐
Addition without addition, subtraction, multiplication, Division
C语言实现迷宫问题
Learning bit segment (1)
R language book learning 03 "in simple terms R language data analysis" - Chapter 7 linear regression model
Latex combat notes 3- macro package and control commands
Non recursive writing of quick sort
[v2.1] automatic update system based on motion step API (repair bug, increase completion display, support disconnection reconnection and data compensation)
5.学城项目 支付宝支付
Win10弹出USB时出现该设备正在使用的解决方法
每日一题 -- 验证回文串
R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
inner join执行计划变了
继承的所有特征
Custom implementation offsetof
Collection of articles and literatures related to R language (continuously updated)
The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
How to use RPA robot to start the first step of digital transformation of freight forwarding industry?
Flink error: multiple tasks are started, and only one task is executed
Classes and objects (4)
In the post epidemic era, how can enterprise CIOs improve enterprise production efficiency through distance









