如何使用批处理或 vbs 提取电子邮件:pass?

如何使用批处理或 vbs 提取电子邮件:pass?

我有一个名为的文本文件file.txt,其中包含,

[email protected]:
[email protected]:password000
[email protected]:
[email protected]:qwerty123
[email protected]:
[email protected]:iloveyou

我正在运行一个 vbs 程序,

Const SCRIPT_NAME = "Extract E-mail Addresses"
Dim objFSO, objFil, arrAdr, varBuf, varInp, varOtp
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFil = objFSO.OpenTextFile("file.txt")
varBuf = objFil.ReadAll
objFil.Close
arrAdr = Split(FindString(varBuf, "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"), ",")
Set objFil = objFSO.CreateTextFile("results.txt")
For Each varBuf In arrAdr
    objFil.WriteLine varBuf
Next
objFil.Close
Set objFil = Nothing
Set objFSO = Nothing
MsgBox "Extraction complete.", vbInformation + vbOKOnly, SCRIPT_NAME
WScript.Quit

Function FindString(strText, strFind)
    Dim objRegEx, colMatches, objMatch
    Set objRegEx = CreateObject("VBscript.RegExp")
    With objRegEx
        .IgnoreCase = True
        .Global = True
        .Pattern = strFind
        Set colMatches = .Execute(strText)
    End With
    For Each objMatch In colMatches
        FindString = FindString & objMatch.Value & ","
    Next
    If Len(FindString) > 0 Then
        FindString = Left(FindString, Len(FindString) - 1)
    End If
    Set objRegEx = Nothing
    Set colMatches = Nothing
    Set objMatch = Nothing
End Function

预期产量,

[email protected]:password000
[email protected]:qwerty123
[email protected]:iloveyou

但实际结果,

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

我的需求:我喜欢从file.txt文本文件中仅过滤电子邮件:密码。但是,使用上述 vbs,我只能过滤电子邮件地址。请修复我的代码以获得我预期的输出。提前谢谢。

笔记 :不同文本文件的电子邮件和密码可能不同。另外,我对 vbs 也是菜鸟。坦白说,上面的代码是从 Quora 上找到的。请帮帮我。即使是使用批处理程序的相同解决方案对我来说也很好。等待有价值的解决方案 :)

答案1

Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("file.txt")
Buffer = Split(File.ReadAll, vbNewLine)
File.Close
Set File = FSO.CreateTextFile("output.txt")
For Each Line In Buffer
    If Trim(Split(Line & ":", ":")(1)) <> "" Then
        File.WriteLine Line
    End If
Next
File.Close

相关内容