Question : Batch File - Extract Numbers from a text file

Hi there,

You will find attached; a text file from which by using a batch file on Win XP,  I must extract all of the numbers containing 7digits each.

You will also find that the numbers are dupplicated, but in the resulted output, they must be unique.

The result must be output on screen as follows:
5127865
5127847
5118095
5123320
5120834
5115144
5115096
5117736
5117740
5115123
5122365
5257847
5199095
6823320
5120892
5115274
5188096
5117730
5777740
5115166

Thanks for your help,
Rene
Attachments:
 
Source text file to extract the numbers from.
 

Answer : Batch File - Extract Numbers from a text file

Okay, here's a change to get the filename from the command line.  I would recommend running it like this:

cscript EE26314082.vbs //NOLOGO input.txt >output.txt

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
' Make sure the input file name is specified on the command line and get it
If (WScript.Arguments.Count > 0) Then
  filename = WScript.Arguments(0)
Else
  WScript.Echo "No input filename specified."
  WScript.Quit
End If
 
' Read entire input file into a single string variable
Set fso = CreateObject("Scripting.FileSystemObject")
Set input = fso.OpenTextFile(filename)
data = input.ReadAll
input.Close
Set input = Nothing
 
' Create dictionary object to ellininate duplicates
Set dict = CreateObject("Scripting.Dictionary")
 
' Create regular expression template to locae the order numbers
Set re = New RegExp
re.Pattern = "OrderNum=[0-9][0-9][0-9][0-9][0-9][0-9][0-9]&"
re.IgnoreCase = True
re.Global = True
 
' Loop through each match, grap order number, and if not already found add to dictionary
for Each hit In re.Execute(data)
   order=Mid(hit.Value, 10, 7)
   If Not dict.Exists(order) Then
      dict.Add order, 0
   End If
Next
 
' Output list of unique order numbers now
For Each o In dict
   Wscript.Echo o
Next
Random Solutions  
 
programming4us programming4us