great77
great77

Reputation: 143

VBscript to search file

At the moment, I have a large text file which batch file can not handle to search the lines. The code below can search the value "9200.... 9300 " if the number of lines in that text file is not long. Even the problem is also that this code returns the value in the same line with 9200.... I only want to crop the value 9200 range to 9300

But whenever, I used it for the large text file (500MB), it is gives strange character. I think I need VBScript to find only this number and I will display that in a message.

The code is

for /f "usebackq delims=* tokens=5" %i in (`findstr "9201.. 9200.." data.mud`) do @echo %I

Thank you.

Upvotes: 0

Views: 315

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200283

Try something like this:

Set fso = CreateObject("Scripting.FileSystemObject")

Set re = New RegExp
re.Pattern = "\d+"
re.Global  = True

filename = "C:\path\to\data.mud"
lb = 9200
ub = 920150

Set f = fso.OpenTextFile(filename)
Do Until f.AtEndOfStream
  For Each m In re.Execute(f.ReadLine)
    n = CLng(m.Value)
    If n >= lb And n <= ub Then WScript.StdOut.WriteLine n
  Next
Loop
f.Close

You need to run this script with cscript.exe:

cscript //NoLogo C:\path\to\your.vbs

Upvotes: 1

Related Questions