1.

Solve : replacing all '.' in 315k text file with other text. Cant do with replace =(?

Answer»

I have a text file that is 315k in size containing a query from a database that I dumped out to a text file. I have added '.' (periods) into the 38000 lines of info and want to replace this '.' with other ascii text without any spaces. I tried doing this with notepad replace and it completed about 10 lines and then notepad became unresponsive. I am guessing that 38000 lines is too much for notepad and I could BREAK it into smaller chunks for notepad to chew on, but figured I'd check here first to see if anyone knew of a way to do this using batch which may not crash LIKE window$ notepad on huge text files.

The original query was just raw text and in order to add text leading into each item on each line, I wrote a quick macro using jitbit macro creator to place a "." (period) then down arrow and left arrow and repeat with a goto statement. This worked perfect and took a while to chug through the 38000 lines at 15MS per line to execute with 5ms delays that i added.

My plans were to use the periods as tags for notepad to replace the periods with other text later on that is about 20 characters in length that ends with = and bound tight with the DATA on each line. Then i was going to run this 38000 lines with the repeated instructions ending in = before each individual item and have that run for a few hours to chug out an analysis.

Without a unique marker tag, you cant use the find and replace all feature, so I planted a period before each item and was hoping after that to just replace all periods with the 20 character instruction that ends in = before the data on each line, save it and then run it through the final process.

Any suggestions if batch is unable to find all "." and replace with "merge_data_xxxxxxxxxx="

ThanksA VBSCRIPT should do the job:

Code: [Select]Dim Inputfile
Dim Outputfile
Dim SearchFor
Dim ReplaceWith
Inputfile = WScript.Arguments(0)
OutputFile = WScript.Arguments(1)
SearchFor = WScript.Arguments(2)
ReplaceWith = WScript.Arguments(3)
WScript.Echo "Using Input file:" + Inputfile
WScript.Echo "Using Output file:" + Outputfile
WScript.Echo "Searching for:" + SearchFor
WScript.Echo "Replacing with:" + ReplaceWith
Dim FSO
Dim InStream,OutStream
Dim LineRead
Set FSO = CreateObject("Scripting.FileSystemObject")
Set InStream = FSO.OpenTextFile(Inputfile)
Set OutStream = FSO.CreateTextFile(OutputFile)

WScript.Echo TypeName(InStream)
Do Until InStream.AtEndOfStream
'Read a line from the input file.
LineRead = InStream.ReadLine()
'perform the replacement.
LineRead = Replace(LineRead,SearchFor,ReplaceWith)
'write to the output file.
OutStream.WriteLine LineRead



Loop
InStream.Close()
OutStream.Close()

execute like so:

Code: [Select]CScript replacer.vbs inputfile.txt outputfile.txt . "Replaced text"
Code: [Select]echo off
setlocal enabledelayedexpansion
if exist output.txt del output.txt
set SearchFor=.
set ReplaceWith=merge_data_xxxxxxxxxx=
for /f "delims=" %%A in (input.txt) do (
set line1=%%A
set line2=!line1:%SearchFor%=%ReplaceWith%!
echo !line2!>>output.txt
)

Cool I will give that a shot. Many Thanks!!



Discussion

No Comment Found