Try this:
Option Explicit
Dim file, domain(), users(), i, j, temp, tmparr
If WScript.Arguments.Count=0 Then
WScript.Echo "Required filename not specified....Quitting"
wscript.quit()
End If
file=WScript.Arguments(0)
UpdateArrays file, domain, users
on error resume next
i=ubound(users)
if err.number then
wscript.Echo "No users...Quitting"
wscript.quit
end if
i=ubound(domain)
if err.number then
wscript.Echo "No domain...Quitting"
wscript.quit
end if
on error goto 0
for i=ubound(domain)-1 to 0 Step -1
for j=0 To i
if domain(j)>domain(j+1) then
temp=domain(j+1)
domain(j+1)=domain(j)
domain(j)=temp
end if
next
next
for i=0 To ubound(users)
for j=1 To ubound(domain)
if (domain(j)>users(i)) Then
tmparr=Split(Users(i),":")
temp=tmparr(1) & " = "
tmparr=split(domain(j-1),":")
temp=temp & tmparr(1)
wscript.echo temp
exit for
elseif users(i)>domain(ubound(domain)) then
tmparr=Split(Users(i),":")
temp=tmparr(1) & " = "
tmparr=split(domain(ubound(domain)),":")
temp=temp & tmparr(1)
wscript.echo temp
exit for
end if
next
next
Sub UpdateArrays(file,ByRef ar1,ByRef ar2)
Const ForReading=1
Dim fso,infile,i1,i2,line
Dim regex1,regex2,match,matches1,matches2
Set regex1=New RegExp
Set regex2=New RegExp
regex1.Pattern="^\d+:\w+\\\w+$"
regex2.Pattern="^\d+:\w+\s\w+$"
regex1.Global=True
regex2.Global=True
Set fso=CreateObject("Scripting.FileSystemObject")
if (Not fso.FileExists(file)) Then
WScript.Echo file & " does not exist...Quitting"
WScript.Quit()
End If
Set inFile=fso.OpenTextFile(file,ForReading)
i1=0
i2=0
Do While Not infile.AtEndOfStream
line=infile.ReadLine
Set matches1=regex1.Execute(line)
Set matches2=regex2.Execute(line)
for each match in matches1
redim preserve ar1(i1)
line=Split(line,":")
ar1(i1)=Right(String(4,"0") & line(0),4) & ":" & line(1)
i1=i1+1
next
for each match in matches2
redim preserve ar2(i2)
line=Split(line,":")
ar2(i2)=Right(String(4,"0") & line(0),4) & ":" & line(1)
i2=i2+1
next
loop
infile.close()
End Sub