输入以下代码
<job id="vbs">
<script language="VBScript">
Const ForReading = 1
Dim objFSO, objFile, i
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("test.txt", ForReading)
Do While objFile.AtEndOfStream <>True
objFile.ReadLine
i = i + 1
Loop
objFile.Close
Wscript.Echo i
</script>
</job>
把"test.txt"改成你要的文件就可以统计该文件的行数
改成可以输入的文件名的,可以输入多个文件名,每个文件名用空格隔开
<job id="HowManyLines">
<script language="VBScript">
Const ForReading = 1
Dim strMsg, fileNames, objFile, lineCount(100)
set objFSO = CreateObject("Scripting.FileSystemObject")
set WshShell = WScript.CreateObject("WScript.Shell")
strMsg = InputBox("Please enter your file name:")
fileNames = Split(strMsg, " ", -1, 1)
For i = 0 To UBound(fileNames)
Set objFile = objFSO.OpenTextFile(fileNames(i) &".txt", ForReading)
Do While objFile.AtEndOfStream <>True
objFile.ReadLine
lineCount(i) = lineCount(i) + 1
Loop
objFile.Close
Next
strMsg = ""
For i = 0 To UBound(fileNames)
strMsg = strMsg &lineCount(i)&" "
Next
MsgBox(strMsg)
</script>
</job>
如果你连文件名都不想输,就用下面这个,指定下目录,会统计出该目录下所有txt文件的行数
<job id="HowManyLines">
<script language="VBScript">
Const ForReading = 1
Dim objFSO, fold, f, strMsg, fileNames(100), objFile, lineCount(100),files,i
set objFSO = CreateObject("Scripting.FileSystemObject")
set fold = objFSO.GetFolder("C:\Documents and Settings\")
set files = fold.Files
For Each f in files
If objFSO.GetExtensionName(f) = "txt" Then
Set objFile = objFSO.OpenTextFile(f, ForReading)
Do While objFile.AtEndOfStream <>True
objFile.ReadLine
lineCount(i) = lineCount(i) + 1
Loop
objFile.Close
fileNames(i) = f.Name
i = i + 1
End If
Next
strMsg = ""
For i = 0 To UBound(fileNames)
If fileNames(i)<>"" Then
strMsg = strMsg &fileNames(i) &":" &lineCount(i)
strMsg = strMsg &Chr(13)
End If
Next
MsgBox(strMsg)
</script>
</job>
Just make a try!
打开txt文件循环读取
读取一行
按空格分隔或自己按长度取相应字段,
保存到数据库,按日期,内部ip,外部ip,时间,访问id等
最后,按需要统计 select count(1) from 表名 group by 日期,外部ip
可以使用VBA实现,通过读取TXT文件,将其路径及行数写入当前工作表中。
步骤如下:
新建一个Excel工作簿,右键查看代码(或者Alt+F11)打开VBE编辑器;
插入一个模块,先清空里面的代码,再将代码粘贴到右侧代码窗口;
按F5运行,根据提示选择要读取的TXT文档,完成。
效果如下:
VBA获取TXT文档行数
文件链接:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)