当前位置:网站首页>使用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
有了上面的处理,后面可以做的事情就比较多了。
边栏推荐
猜你喜欢

Cdr2022 serial number coreldraw2022 green key

win10字体模糊怎么调节

EndnoteX9簡介及基本教程使用說明

Building a custom CNN model: identifying covid-19

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录

Leetcode - 第2天

Huawei equipment configuration hovpn

win11怎么看电脑显卡信息

Servlet get form data

R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest
随机推荐
Popular science | what are the types of NFT (Part 1)
[niuke.com] ky41 put apples
如何查看win系统的安装日期
Classes and objects (4)
重温c语言一
C language implements eight sorts (3)
ESP32C3 Arduino库使用方法
【学术相关】申请审核制下,到双一流大学读博的难度有多大?
Usage of esp32c3 Arduino Library
每日一题 -- 验证回文串
EndnoteX9简介及基本教程使用说明
图书管理系统
Matlab: solution of folder locking problem
R语言相关文章、文献整理合集(持续更新)
The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
[academic related] under the application review system, how difficult is it to study for a doctoral degree in a double first-class university?
LaTex实战笔记 3-宏包与控制命令
自定义实现offsetof
Dynamic memory management (1)
go io模块