vbs同时读取二行并分析
我有个vbs的问题。
有一个文本。
1.txt文件内容如下
interface Ip-Trunk1
description TO-[RT01-NE80E]
ip address 100.1.50.26 255.255.255.252
isis enable 1
isis circuit-level level-2
isis cost 498 level-2
isis authentication-mode md5 ]4P*V79$MK":2)Z^63Xa1!!!
mpls
mpls ldp
trust upstream default
#
interface Ip-Trunk2
description TO-[RT02-NE80E]
ip address 100.2.74.1 255.255.255.252
isis enable 1
interface Ip-Trunk2
description TO-[RT02-NE80E]
ip address 100.2.74.1 255.255.255.252
ospf xxx
....文本比较大
我想这样,读有ip address的行,同时分析他的下一行是否有关键字2,如果有就执行A,没有就执行B。我要如何做呀
[解决办法]
On Error Resume Next sFile = "C:\Users\Administrator\Desktop\a.txt" sComp = LCase("ip address") '特征码 nLen = Len(sComp) If nLen < 1 Then WScript.Echo "请指定特征码!" WScript.Quit End IfSet oFSO = CreateObject("Scripting.FileSystemObject")Set oFile = oFSO.OpenTextFile(sFile) If Err Then WScript.Echo "打开文件失败!" WScript.Quit End IfDo Until oFile.AtEndOfLine sRead = oFile.ReadLine '下面这里也可以根据需要改成instr之类的判断不在开头的情况 If LCase(Left(sRead,nLen)) = sComp Then MySub oFile.ReadLine,oFile.Line - 1 End If LoopSub MySub(str,line) If Not InStr(str,"2") = 0 Then WScript.Echo "你真贰!" & vbCrLf & "在第" & line & "行" Else WScript.Echo "你不贰!" & vbCrLf & "在第" & line & "行" End IfEnd Sub