Since you have many .txt files, it makes sense to do a simple automation instead of extracting the values from each file manually. I suggest to use the WSH VBScript below:
strRes = ""
For Each strPath In WScript.Arguments
With CreateObject("Scripting.FileSystemObject")
If .FileExists(strPath) Then
strRes = strRes & .GetFileName(strPath) & vbCrLf
strCont = LoadTextFromFile(strPath, "us-ascii")
With CreateObject("VBScript.RegExp")
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "-A(\d{3})"
Set objMatches = .Execute(strCont)
For Each objMatch In objMatches
strRes = strRes & objMatch.SubMatches(0) & vbCrLf
Next
End With
End If
End With
Next
ShowInNotepad strRes
Function LoadTextFromFile(strPath, strCharset)
With CreateObject("ADODB.Stream")
.Type = 1 ' TypeBinary
.Open
.LoadFromFile strPath
.Position = 0
.Type = 2 ' adTypeText
.Charset = strCharset
LoadTextFromFile = .ReadText
.Close
End With
End Function
Sub ShowInNotepad(strToFile)
Dim strTempPath
With CreateObject("Scripting.FileSystemObject")
strTempPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\" & .GetTempName
With .CreateTextFile(strTempPath, True, True)
.WriteLine strToFile
.Close
End With
CreateObject("WScript.Shell").Run "notepad.exe " & strTempPath, 1, True
.DeleteFile (strTempPath)
End With
End Sub
Just paste this code to the notepad, save as text file, and manually replace .txt
file extension with .vbs
. Then all that you need is select your text files in explorer window, and drag and drop them onto the script.
For the files you have shared I has the output as follows:
30_SCH51BQ139.txt
036
30_SCH51BQ141.txt
038
30_SCH51BQ144.txt
040
30_SCH51BQ147.txt
043
Is this a binary file? What do you want to do with the data when you have it? Is it always in the same format (letter + 3 numbers)? Does it always have
| -
before it? – DavidPostill – 2016-03-10T22:15:52.170I want to compare it with the database. Yes, it is always the same format as you said, also | - is always before. Regarding binary file question, I am not familiar with that so I can't answer you... – kiki1989sb – 2016-03-11T23:47:33.467