Advertisement

09.08.2008 at 06:49AM PDT, ID: 23712004
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.5

Vbscript Regular Expression Find and Replace on 100mb Text File

Asked by Diammond in VB Script, Miscellaneous Programming, Regular Expressions

Tags:

I have vscript code that uses a regular expression to do a find and replace in a text file.  The code works perfectly on smaller files.  However, when searching a very large file (100mb), the find and replace never completes.  I have tried ReadAll, ReadLine and now Read Bytes in attempt to speed up the search and replace process.  I am reposting this question due to no resolution the first time around.  I am way past due on getting this code to work.  I am assigning the maximum points for this question.  At this time, I could really use a solution as opposed to a suggestion.  Your response would be greatly appreciated.  Thank you for your time!
Diammond


strserver = "."
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const TristateFalse = 0
Const OverwriteExisting = True

dateStamp = Date()
timeStamp = Time()
 

'CREATE DICTIONARY OBJECT FOR PHONE-NUMBER-LIST.TXT AND READ THE FILE
set objList = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
Set objFile = objFSO.OpenTextFile("c:\Phone-Number-List.txt", ForReading)
strSearchString = objFile.ReadAll
objFile.Close

'CREATE REGULAR EXPRESSION TO SEARCH FOR PHONE NUMBERS
'THEN COMPARE PHONE NUMBERS FOUND IN DATAFILE.TXT WITH PHONE NUMBERS IN Phone-Number-List.txt
set re = New RegExp
re.global = true
re.pattern = "#Phone" & vbCRLF & Chr(34) & "\d{3}\d{3}\d{4}" & Chr(34)
 
Set objMatches = re.Execute(strSearchString)

For Each objMatch in objMatches
    objList.Add objMatch.Value, ""
Next

dim objTS

Set objFile = objFSO.GetFile("C:\datafile.txt)
Set objTS = objFile.OpenAsTextStream(ForReading, TriStateFalse)
strSearchString = objTS.Read(objFile.Size)
 
Set objMatches = re.Execute(strSearchString)

objFSO.CopyFile "c:\REPLACED#s.LOG", "c:\REPLACED#s.bak", OverwriteExisting

Set objFile = objFSO.OpenTextFile ("c:\REPLACED#s.LOG", ForWriting)
 objFile.Write ""
 objFile.Close

icount = 0
For Each objMatch in objMatches
    If Not objList.Exists (objMatch.Value) Then
        strSearchString = Replace(strSearchString, objMatch.Value, "#Phone" & vbCRLF & Chr(34) & "4047895400" & Chr(34))
icount = icount + 1

'WRITE TO REPLACED#s.LOG WITH PHONE NUMBERS THAT HAVE BEEN REPLACED
Set objFile = objFSO.OpenTextFile("C:\REPLACED#s.LOG", ForAppending)

objFile.WriteLine(objMatch.Value) & " " & "replaced with phone number" & " " & Chr(34) & "4047895400" & Chr(34) & " " & dateStamp &  " " & timestamp
objFile.Close

Set objFile = objFSO.OpenTextFile("C:\REPLACED#s.LOG")
strLogFileContents = objFile.ReadAll
objFile.Close

End If
Next

'WRITE TO datafile.txt REPLACING INVALID PHONE NUMBERS
Set objFile = objFSO.OpenTextFile("c:\datafile.txt", ForWriting)
objFile.WriteLine strSearchString
objFile.Close

Set objFile = objFSO.OpenTextFile("C:\REPLACED#s.LOG", ForWriting)
objFile.WriteLine "Found " & iCount & " matches total."
objFile.WriteLine strLogFileContents
objFile.Close  

Start Free Trial
 
Loading Advertisement...
 
[+][-]09.08.2008 at 07:23AM PDT, ID: 22417633

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 08:10AM PDT, ID: 22418156

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 09:23AM PDT, ID: 22418950

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 11:54AM PDT, ID: 22420338

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 11:56AM PDT, ID: 22420356

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 11:57AM PDT, ID: 22420375

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 12:15PM PDT, ID: 22420579

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 02:47PM PDT, ID: 22421993

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 03:37PM PDT, ID: 22422269

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 08:52PM PDT, ID: 22424170

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 07:46AM PDT, ID: 22427924

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 09:11AM PDT, ID: 22429009

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 09:28AM PDT, ID: 22429180

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Miscellaneous Programming, Regular Expressions
Tags: vbscript
Sign Up Now!
Solution Provided By: ddrudik
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.09.2008 at 12:15PM PDT, ID: 22431081

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 12:33PM PDT, ID: 22431317

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 12:51PM PDT, ID: 22431504

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628